Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Listing more than one item of a table

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Listing more than one item of a table

Postby Guerlot » Sat Feb 15, 2003 1:06 pm

Hi,

I have the following php script, which is working really well :

<?php
require ("config.php");
$db = mysql_connect("$hostname", "$username", "$password");
mysql_select_db("$database");
$result = mysql_query("SELECT id,song_artiste FROM $table WHERE song_artiste LIKE '%$q%' OR song_title LIKE '%$q%' OR song_album LIKE '%$q%' OR song_lyrics LIKE '%$q%' ORDER BY song_artiste");
$count = mysql_num_rows($result);
echo "<OL>\n";
while ($myrow = mysql_fetch_row($result)) {
printf("<LI><A HREF=\"display.php?id=%s\">%s</A>", $myrow[0], $myrow[1]);
}
echo "</OL>\n";
mysql_close();
?>


When calling that script, it shows a list that looks like that:
1.Thorogood, George
2.Tenacious D
3.Love and Rockets
etc.
and By clicking on the artist, I have a new page giving me the title, the artist, the album and the lyrics.

In the list, I would like to show the song title beside the artist as well in order to look like that:
1.Thorogood, George - Bad to the Bones
2.Tenacious D - Wonderboy
3.Love and Rockets - Ball of Confusion

I tried a few tweaks like adding order by song_artiste,song_title
but I can't make it work

Can somebody help me on that one?

Thanks in advance!
Guerlot
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Oct 05, 2002 6:47 am
Location: Hull, Quebec, Canada

Postby *JaH* » Sat Feb 15, 2003 1:12 pm

"SELECT id,song_artiste,song_title FROM $table WHERE song_artiste LIKE '%$q%' OR song_title LIKE '%$q%' OR song_album LIKE '%$q%' OR song_lyrics LIKE '%$q%' ORDER BY song_artiste"

please read something about writing queries at http://www.mysql.com if you want to know more about this :)
*JaH*
New php-forum User
New php-forum User
 
Posts: 80
Joined: Fri Jan 31, 2003 4:18 pm

Postby Guerlot » Sat Feb 15, 2003 1:24 pm

This was one of my attempts I did.
I did that change you are mentionning.
After that, I now have to change that line:
printf("<LI><A HREF=\"display.php?id=%s\">%s</A>", $myrow[0], $myrow[1]);

If I add $myrow[2] at the end, it changes nothing.

But I know that I'm close to it, because by changing $myrow[1] for $myrow[2], it gives me the list of the titles only.

I'll go take a look to your link.

Thanks
Guerlot
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Oct 05, 2002 6:47 am
Location: Hull, Quebec, Canada

Postby pootergeist » Sat Feb 15, 2003 1:42 pm

printf("<LI><A HREF=\"display.php?id=%s\">%s</A>", $myrow[0], $myrow[1]);

printf is a formatted echo according to the terms - so %s = in both cases $myrow[0]

I prefer just using echo so would use

echo '<LI><A HREF="display.php?id=' .$myrow[0]. '">' .$myrow[0]. '</A> - ' .$myrow[1];
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby Guerlot » Sat Feb 15, 2003 1:46 pm

You are the man!

It worked. Thanks a lot!
Guerlot
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Oct 05, 2002 6:47 am
Location: Hull, Quebec, Canada


Return to PHP coding => General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.