Jump to content

Making a list


leodirk

Recommended Posts

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.

Link to comment
Share on other sites

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();
?>

 

Link to comment
Share on other sites

<?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();
?>

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.