List an array in a specific order...

777php

Diamond Member
Jul 17, 2001
3,498
0
0
I have website that people can come and modify sites via a web interface. I have a navigational bar that I want people to be able to order buttons on their own. Each page has a table in the database and a listing of all the categories to be listed on the navigational bar.

Site/server stats
Redhat 7.0 running apache with php, mysql

IE

Database: WebPages
Table: TestPage

Navbar | Order | Link to image

Main 1 /path/to/image and URL
Pictures 3 /path/to/image and URL
News 4 /path/to/image and URL
Events 2 /path/to/image and URL
Links 5 /path/to/image and URL

I want for mysql to display the array by the order number, not in the order they are listed in the database. Anyone know how to do this?

To make it a bit more compliated....I want to have php echo the /path/to/image and URL which is written in html so that it can be displayed on the page.
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
In a less confusing explanation I will try to correlate with e-commerce site. User does a search for all products by IBM sorted by price. Instead of listing the product name: description and then price, I want the query to grab the all the category names: and then its order number. Once the names and order has been retreived then, I want to be printed by order number the, /path/to/image and URL. Still a bit confusing but, better than before.
 

Wizkid

Platinum Member
Oct 11, 1999
2,728
0
0
add:

ORDER BY order_number

to the SQL statement, where order_number is the name of the field that stores the order number.
 

crystal

Platinum Member
Nov 5, 1999
2,424
0
76
Code in the html link codes so it will displays it as the link in your sql statement.
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
I've changed the records in the database so that stored in location is a php include command with the path to a include file which then contains the html for the link and image.

Now I just need a mysql script to display the array

I've written the query in this manner:

//All that database connect stuff goes here
$query = "SELECT * from TestPage ORDER BY Order";
$results = mysql($query)
$num_results = mysql_num_rows($result);

for ($i=0; $i <$num_results; $i++)
$row = mysql_fetch_array($results);
echo ($row["location"]);
}

Now I get a "Supplied argument is not a valid MySQL result resource" error.

I want for php to echo the the include command, one right after another sorted by the order number each include is assigned until there is nothing to display. Can someone dissect my code or provide me with code that might work?

Thanks guys, I already feel stupid beign a mysql newb.
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
$results = mysql_query($query)

yeah...thats what i actually have in my code but I mis-typed it here.
 

777php

Diamond Member
Jul 17, 2001
3,498
0
0
Hey guys, I figured it out....this worked for me

<?php


mysql_connect($dbhost,$dbusername,$dbuserpassword);
@mysql_select_db($default_dbname) or die( "Unable to select database");
$query = "select * from TestPage";
$result = mysql_query ($query);


if ($result){

echo "<?php ";

$numOfRows = mysql_num_rows ($result);
for ($i = 0; $i < $numOfRows; $i++){
$location = mysql_result ($result, $i, "location");

echo $location;
echo "
";

}

echo "?>";

}
else{

echo mysql_errno().": ".mysql_error()."
";
}
mysql_close ();
?>