View Full Version : array help

08-25-2007, 10:27 PM
ok I have the following structure of data that I want to store in a array:

t_id,name,b_id_blog for each tag how can I store these 3 pieces data together in a array? so when I edit them I can do a Udate SQL statement?

08-26-2007, 04:20 AM
post your simple code of editing one type. maybe you can do something with associative array, but it all depends on what you need eg

$t_id_code array (
"t_id" => "sql statement id",
"name" => "sql statement name",
"b_id_blog" => "sql statement b_id"

Then use it in your function, with foreach or just crude array selection, something like

$t_id_code['t_id'], yould then use the sql statement you have for id :)

Btw, if you set your ID to auto_increment, it will be stored as 1,2,3.. etc, without the need to set it in any way...

08-26-2007, 04:28 AM
Ideally(at least to me) it would be in an array that looked like

$array = array(
'123' => 'tag',
'456' => 'othertag'

// This is so you can
foreach($array as $id => $tag)
// update

08-26-2007, 03:59 PM
Yeah, t_id is automatic, this is for figuring out updating of tags for the editing of a post.

08-26-2007, 06:42 PM
well for editing posts you can only use ID to reach the post. eg, if you see on forums something like showthread.php?t=122259, t=122259 it's the id of a post. if you ever moderated forum (rg vbulletin) you have select option near post.

when you select post you want to move/delete/lock/stick, you reach it by id.

i can't say more couse i just started learning SQL, but if you have some code you started, i guess ppl here could help you more

08-26-2007, 08:05 PM
Here is the code I have so far

* Function Update POst
* This handles the changes to the post, With out updating the POST date
function updatePost($postID,$title,$author,$bdate,$body,$tags){
$sql ="UPDATE blog SET title='$title',body='$body',author='$author',date='$bdate' WHERE id='$postID' ";
$results = connect($sql);
if($results == false){
echo "<div class=\"error_msg\">Sorry Couldn't Update the Blog Post</div>";
$rmTags = "DELETE tags.* FROM tags WHERE tags.b_id_blog = '$postID'";
$tags = explode(",",$tags);
foreach($tags as $tag){
$mktags = "INSERT INTO tags VALUES ('','$tag','$postID')";
$results = connect($mktags);
if($results == false){
echo '<div class="error_msg">Sorry Couldn\'t Update the Blog Post due to the Tags.</div>';
echo '<div class="ok_msg">Blog Post Updated Successfully.</div>';

I'm gotta figure out still is storing html in side the post I'm thinking about using html_encode and then when getting the post html_decode. This is a inefficient way to handle the updating the post tags. Suggestions?

08-26-2007, 08:23 PM
when I go to use the function I get the following error

Unable to query local database Unknown column 'id' in 'where clause'
UPDATE blog SET title='HTML encoding test',body='moos3',author='<p>This is <b>A test of HTML Storing</b> in the Database.</p><p>Old tags: php,site,test New tags: admin,functions,eskimo,maine',date='1188151333' WHERE id=''

08-26-2007, 08:39 PM
$postID is apparently empty, and you don't have an "id" column.

08-26-2007, 09:21 PM
ok, fixed that but now its deleting the post on update.

08-26-2007, 09:49 PM
ok, fixed everything but now I'm having a date issue, when I use the unix timestamp and then push it back into the database it ****s the bed and makes the post be in 1969. Suggestion? if I use the date function and then push it back to the data its not going to change it is ?

08-26-2007, 10:53 PM
Check the database to make sure the timestamp is there. As long as you don't overwrite the timestamp when you use date() it shouldn't change.

08-27-2007, 12:45 AM
Unable to query local database You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE b_id='20'' at line 1
UPDATE blog SET title='test post',body='this is a test that will be updated with content. This is new content. old tags php,site,tes new tags beer,i,rock,php,world',author='moos3', WHERE b_id='20'

I removed the date and now get the above error.

08-27-2007, 12:48 AM
Remove the comma after author='moos3'.