Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Double Check Data in Query

Codes here !

Moderators: macek, egami, gesf

Double Check Data in Query

Postby zeep25 » Fri Mar 14, 2003 7:33 pm

hi ... im still a beginner at php+mysql ... is there a way to get data from a field and take out the double entries ... since i have the artist name on each row .. and some rows have the same artist .. i jsut want to display each artist's name once ..

heres my code :

Code: Select all
<?
// open database connection
$connection = mysql_connect("XXX","XXX","XXX") or die ("Unable to
connect!");
// select database
mysql_select_db("XXX") or die ("Unable to select database!");
// generate and execute query
$query = "SELECT artist,id FROM lyrics ORDER BY artist";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print title with links to edit and delete scripts
while($row = mysql_fetch_object($result))
{
?>

<tr width="694">
<td class=primary width="35" align=center height=1>
<img border=0 src=images/band.gif width=32 height=32></td>
<td class=primary width="480" height=1>
<p align=left><a href="artist.php?artist=<? echo $row->artist;?>"><? echo $row->artist; ?></a></td></tr>


<?
}
}
// if no records present
// display message
else
{
?>
DATABASE EMPTY
<?
}
// close connection
mysql_close($connection);
?>


also is there a way to display it so i have two colums in the page .. like :

A | D
B | E
C | F
zeep25
New php-forum User
New php-forum User
 
Posts: 9
Joined: Fri Mar 14, 2003 7:23 pm

Postby Romantik » Sat Mar 15, 2003 2:25 am

"SELECT DISTINCT(artist),id FROM lyrics ORDER BY artist";
Romantik
New php-forum User
New php-forum User
 
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson

Postby zeep25 » Sat Mar 15, 2003 2:36 pm

hmm strange .. its not workin .. still shows duplicates .. would i have to change my show result code in any way ?
zeep25
New php-forum User
New php-forum User
 
Posts: 9
Joined: Fri Mar 14, 2003 7:23 pm

Postby zeep25 » Mon Mar 17, 2003 5:10 pm

ok it worked .. i used :

Code: Select all
"SELECT artist,id FROM lyrics group by artist"
zeep25
New php-forum User
New php-forum User
 
Posts: 9
Joined: Fri Mar 14, 2003 7:23 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

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