jandrews3 Posted July 21, 2008 Share Posted July 21, 2008 Why would the following code return only single digits for $id? The values for id in the database are 0, 2, 3, 4, 5, 6, 7, 44, 45, but the below code only returns single digits. I'm new to arrays so I'm guessing I'm making some kind of mistake there, but I don't know. <? $count = 0; $query1 = "SELECT * FROM scheduled_events WHERE date != 'title' ORDER BY pos"; $result1= mysql_query($query1) or die("Could not perform query: ".mysql_error()); while ($row1 = mysql_fetch_array($result1)){ $date[$count] = $row1['date']; $event[$count]= $row1['event']; $pos[$count] = $row1['pos']; $id[$count] = $row1['id']; $count++; $count_max = $count; } ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 looks okay.. add this to the end. echo "<pre>"; print_r($id); echo "</pre>"; whats displayed ? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 21, 2008 Share Posted July 21, 2008 I don't see anything wrong with your code either, but it can be written a little simpler: <?php $date = array(); $event = array(); $pos = array(); $id = array(); $query1 = "SELECT * FROM scheduled_events WHERE date != 'title' ORDER BY pos"; $result1= mysql_query($query1) or die("Could not perform query: ".mysql_error()); while ($row1 = mysql_fetch_assoc($result1)){ $date[] = $row1['date']; $event[]= $row1['event']; $pos[] = $row1['pos']; $id[] = $row1['id']; } $count_max = count($date); ?> Ken Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted July 21, 2008 Author Share Posted July 21, 2008 To answer what is displayed, always the left most digit. If I select the item with the id 44, then it returns 4. The id 45 does the same. When I changed the 7 to a 71 manually, the script only displayed the 7. Here is the full code: <body bgcolor="cccccc"> <? $count = 0; $query1 = "SELECT * FROM scheduled_events WHERE date != 'title' ORDER BY pos"; $result1= mysql_query($query1) or die("Could not perform query: ".mysql_error()); while ($row1 = mysql_fetch_array($result1)){ $date[$count] = $row1['date']; $event[$count]= $row1['event']; $pos[$count] = $row1['pos']; $id[$count] = $row1['id']; $count++; $count_max = $count; } ?> <table border="0" cellpadding="0" cellspacing="0" width="375" style="font-family: helvetica; font-size: 9pt;"> <tr> <td colspan="3"><b>Instructions:</b></td> </tr> <tr> <td height="5"></td> </tr> <tr> <td colspan="3">Select “Edit” to alter an entry or “Delete” to delete it. Or select “Add Entry” at the bottom to add to scheduled events. </td> </tr> <tr> <td height="15" </tr> <tr> <? $count = 0; while ($count < $count_max){ print "<td width=\"75\" style=\"font-size: 8pt;\"><a href=\"manage_events_edit1.php?id=".$id[$count]."\" target=\"manage1\"><u>Edit</u></a> / <a href=\"manage_events_delete.php?id=".$id[$count]."\" target=\"manage1\"><u>Delete</u></a></td>"; print "<td style=\"font-size: 8pt;\">".$pos[$count]."- </td>"; print "<td style=\"font-size: 8pt;\">".$event[$count]."</td>"; print "</tr><tr><td height=\"15\"></td></tr><tr>"; $count++; } ?> </tr> <tr> <td height="10" </tr> <tr> <td><b>- OR -</b></td> </tr> <tr> <td height="10"></td> </tr> <tr> <td colspan="3"><a href="manage_events_add1.php"><img src="resources/add_entry.jpg" border="0"></a></td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 does the link work ? manage_events_edit1.php?id=71 ? if so increase the width of the cells Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted July 21, 2008 Author Share Posted July 21, 2008 No, it doesn't work. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 can you try this test looks okay.. add this to the end. echo "<pre>"; print_r($id); echo "</pre>"; whats displayed ? Also view source, to get the results (just the array part) Quote Link to comment Share on other sites More sharing options...
blueman378 Posted July 21, 2008 Share Posted July 21, 2008 your retrieving the values from mysql, is that length set to only 1 digit by any chance, thats the only possible reason i can see, oh yeah you have a few formatting errors such as: <body bgcolor="cccccc"> should be <body bgcolor="#cccccc"> and you need to close this: <tr> <td height="15" </tr> Quote Link to comment Share on other sites More sharing options...
peranha Posted July 21, 2008 Share Posted July 21, 2008 Also, dont start php with the short tags <? always start with the normal tags <?php short tags may not be supported on some servers. Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted July 21, 2008 Author Share Posted July 21, 2008 The print_r ($id) still returned the same problem. I have manually checked the values in the database. They are 2, 3, 4, 5, 6, 7, 44, 45. I don't understand how the values could be in the database, but only pull the first digit. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 21, 2008 Share Posted July 21, 2008 Okay.. test 2 let see what we are getting back from the query <?php $count = 0; $query1 = "SELECT * FROM scheduled_events WHERE date != 'title' ORDER BY pos"; $result1= mysql_query($query1) or die("Could not perform query: ".mysql_error()); while ($row1 = mysql_fetch_array($result1)){ echo "#$count#"; //ADD (only to help find it) print_r($row1); //ADD $date[$count] = $row1['date']; $event[$count]= $row1['event']; $pos[$count] = $row1['pos']; $id[$count] = $row1['id']; $count++; $count_max = $count; } ?> Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted July 22, 2008 Author Share Posted July 22, 2008 The output was: #0#Array ( [0] => 2 [id] => 2 [1] => June 16 [date] => June 16 [2] => ITHF Board of Directors Meeting [event] => ITHF Board of Directors Meeting [3] => 2 [pos] => 2 [4] => [take] => ) #1#Array ( [0] => 3 [id] => 3 [1] => June 17 [date] => June 17 [2] => ITHF Annual Membership Breakfast Meeting [event] => ITHF Annual Membership Breakfast Meeting [3] => 3 [pos] => 3 [4] => [take] => ) #2#Array ( [0] => 4 [id] => 4 [1] => June 14-18 [date] => June 14-18 [2] => ITHF's booth #235 in the House of Friendship [event] => ITHF's booth #235 in the House of Friendship [3] => 4 [pos] => 4 [4] => [take] => ) #3#Array ( [0] => 5 [id] => 5 [1] => June 6-19, 2009 [date] => June 6-19, 2009 [2] => Register Now for ITHF's Tour of Britain and Ireland [event] => Register Now for ITHF's Tour of Britain and Ireland [3] => 5 [pos] => 5 [4] => [take] => ) #4#Array ( [0] => 6 [id] => 6 [1] => Late August [date] => Late August [2] => 3rd Quarterly Newsletter out [event] => 3rd Quarterly Newsletter out [3] => 6 [pos] => 6 [4] => [take] => ) #5#Array ( [0] => 7 [id] => 7 [1] => Nov - Dec [date] => Nov - Dec [2] => Renewal reminders out [event] => Renewal reminders out [3] => 7 [pos] => 7 [4] => [take] => ) #6#Array ( [0] => 44 [id] => 44 [1] => Apr. 1-3 [date] => Apr. 1-3 [2] => This is a test entry [event] => This is a test entry [3] => 8 [pos] => 8 [4] => [take] => ) #7#Array ( [0] => 45 [id] => 45 [1] => July 23 [date] => July 23 [2] => This is another test entry [event] => This is another test entry [3] => 9 [pos] => 9 [4] => [take] => ) Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted July 22, 2008 Author Share Posted July 22, 2008 I broke it up so its easier to read: #0#Array ( [0] => 2 [id] => 2 [1] => June 16 [date] => June 16 [2] => ITHF Board of Directors Meeting [event] => ITHF Board of Directors Meeting [3] => 2 [pos] => 2 [4] => [take] => ) #1#Array ( [0] => 3 [id] => 3 [1] => June 17 [date] => June 17 [2] => ITHF Annual Membership Breakfast Meeting [event] => ITHF Annual Membership Breakfast Meeting [3] => 3 [pos] => 3 [4] => [take] => ) #2#Array ( [0] => 4 [id] => 4 [1] => June 14-18 [date] => June 14-18 [2] => ITHF's booth #235 in the House of Friendship [event] => ITHF's booth #235 in the House of Friendship [3] => 4 [pos] => 4 [4] => [take] => ) #3#Array ( [0] => 5 [id] => 5 [1] => June 6-19, 2009 [date] => June 6-19, 2009 [2] => Register Now for ITHF's Tour of Britain and Ireland [event] => Register Now for ITHF's Tour of Britain and Ireland [3] => 5 [pos] => 5 [4] => [take] => ) #4#Array ( [0] => 6 [id] => 6 [1] => Late August [date] => Late August [2] => 3rd Quarterly Newsletter out [event] => 3rd Quarterly Newsletter out [3] => 6 [pos] => 6 [4] => [take] => ) #5#Array ( [0] => 7 [id] => 7 [1] => Nov - Dec [date] => Nov - Dec [2] => Renewal reminders out [event] => Renewal reminders out [3] => 7 [pos] => 7 [4] => [take] => ) #6#Array ( [0] => 44 [id] => 44 [1] => Apr. 1-3 [date] => Apr. 1-3 [2] => This is a test entry [event] => This is a test entry [3] => 8 [pos] => 8 [4] => [take] => ) #7#Array ( [0] => 45 [id] => 45 [1] => July 23 [date] => July 23 [2] => This is another test entry [event] => This is another test entry [3] => 9 [pos] => 9 [4] => [take] => ) Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 22, 2008 Share Posted July 22, 2008 Thats very weird, are you sure the print_r ($id) had the same problem?, is this page live ? The print_r ($id) still returned the same problem. I have manually checked the values in the database. They are 2, 3, 4, 5, 6, 7, 44, 45. I don't understand how the values could be in the database, but only pull the first digit. Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted July 22, 2008 Author Share Posted July 22, 2008 Yeah, I'm sure. Try the link ... http://ositotemp1.org/manage_events.php Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted July 22, 2008 Author Share Posted July 22, 2008 Apparently the solution was to change $id[$count] in each occurence to $tid[$count] as I had $id used in my SESSION script not herein posted. I'm should have posted the entire code. For those people whose time I wasted by not posting the full code, I apologize! Quote Link to comment Share on other sites More sharing options...
blueman378 Posted July 23, 2008 Share Posted July 23, 2008 i might point out you might want to turn register globals off on your server then! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.