Page 1 of 1
really newbie, hopefully an easy answer?
Posted: Fri Aug 22, 2003 1:48 pm
by illmapu
Hi,
I am very new to php so please bear with me if this is simple, but I am stumped.

Right now, I am using this code that counts the number of titles I have, but I want to disply the text from the title. Can someone help?
<?php
require('config.php');
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname,$db) or die(mysql_error());
$title=mysql_query("select title from links");
$title2=mysql_num_rows($title);
?>
This tells me how many titles I have in total, but I need to beable to show what those title descriptions are, if that makes sense?
Please help and thank you in advance!
Posted: Fri Aug 22, 2003 2:47 pm
by BigE
That's pretty simple, you need to use
http://php.net/mysql-fetch-assoc or something similar. An example peice of code would be
Code: Select all
<?php
require('config.php');
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname,$db) or die(mysql_error());
$title=mysql_query("select title from links");
$title2=mysql_num_rows($title);
while ($row = mysql_fetch_assoc($title))
{
echo 'The title is: ' . $row['title'] . '<br>',"\n";
}
?>
That should display all of the titles you selected from the database. Hope that helps.
Thanks!
Posted: Sun Aug 24, 2003 5:53 pm
by illmapu

Thank you, that worked great and the link helped great too!
Is there a trick so that the data pulled doesn't come up as alphabetically? For example, i have 2 pieces of data with numbers as the title and 2 with words, it is organizing them into numbers , then words and alphabetically. I would just like to have the titles come up from the first to the last only. Can you help or give me another great link that I could learn from?
Thanks again in advance!

Posted: Sun Aug 24, 2003 6:53 pm
by BigE
Well... when you select data from a database, it just selects it in the order that it is in, in the database. If you have another field in there you want to order by then use the MySQL function ORDER BY which can be found at
http://www.mysql.com/doc/en/SELECT.html What you probably want to use is ORDER BY title ASC. So your query would look something like
Code: Select all
SELECT title FROM links ORDER BY title ASC
Hope that helps!
Thanks again!
Posted: Tue Aug 26, 2003 7:31 pm
by illmapu

Thanks again for your help, I'm gonig to start reading this forum and php.net for more answers!

Posted: Tue Aug 26, 2003 10:35 pm
by JAM
I recommend taking a peek at
http://se.php.net/tips.php. You can configure your browser to be setup as a quick-help, that I personally think is pretty useful.