leodirk Posted April 18, 2008 Share Posted April 18, 2008 Ok well basically I have a table that lists a ton of items in it which have a name, and ID and some other things. I am trying to get it to repeat the whole list of them ordered by the ID, but because not every number for the ID is used I want to display "Empty" or something for each time there is not an item with that ID. I know it is most likely some pretty easy script but I have been off lately with my PHP scripting x.x.. Thanks. Quote Link to comment Share on other sites More sharing options...
phpretard Posted April 18, 2008 Share Posted April 18, 2008 Do you have any code to post? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted April 18, 2008 Share Posted April 18, 2008 *clap* Thanks, phpretard! beat me to it. Quote Link to comment Share on other sites More sharing options...
leodirk Posted April 18, 2008 Author Share Posted April 18, 2008 Its basically just <?php SQL login here $sql="SELECT * FROM $tbl_name ORDER BY id ASC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ if ($rows['id'] > 0){ echo $rows['name']; echo "<br>"; } } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
morph07 Posted April 18, 2008 Share Posted April 18, 2008 <?php SQL login here $sql1="SELECT * FROM $tbl_name ORDER BY id DSC"; $sql2="SELECT * FROM $tbl_name ORDER BY id ASC"; $result1=mysql_query($sql1); $result2=mysql_query($sql2); $highest=mysql_fetch_field($result1); $id=mysql_fetch_field($result2); for(i=0;i<=$highest->id;i++){ if($id->id > i){//print empty row} else{ //print the user data $id=mysql_fetch_field($result2); } } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
leodirk Posted April 18, 2008 Author Share Posted April 18, 2008 Thanks but uh, I get quite a few errors when using that and trying to fix it x.x dunno why. I'll try to fix it up some more, if I use it as is, it tells me "Parse error: syntax error, unexpected '=', expecting ';' in 'location' on line 21" Quote Link to comment Share on other sites More sharing options...
leodirk Posted April 18, 2008 Author Share Posted April 18, 2008 Er I couldnt find an edit button? Sorry if there is one, I'm just out of it. But anyway, if it helps at all, the IDs i want to display are 1-100 so if that makes it any easier.. Since it wont have to deal with the highest value for the ID, or being over 0.. 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.