News Register Control Panel Private Messages Members List Team Search News Posts About Us

Linux Advisory » Q & A - Discussions » Programming & Coding » stuck with mysql! » Hello Guest [login|register]
Last Post | First Unread Post Print Page | Recommend to Friend | Add Thread to Favorites
Post New Thread Post Reply
Author
Post « Previous Thread | Next Thread »
onzeponze onzeponze is a Male
Lord


Registration Date: 06-17-2003
Posts: 384
Location: India
Linux Distro: Knoppix

Rating:
6 Votes - Average Rating: 3.83

Level: 23 [?]
Experience Points: 49.557
Next Level: 62.494
12.937 point(s) of experience needed for next level

OFFLINE

stuck with mysql! Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Although i'm not a newbie to PHP i'm rather new to MySQL and am ashamed to admit i've got myself stuck. I'm building a rating system for sites, here's the code to read data from the db

//Load the ratings into an array
for($i = 1; $i <= 2; $i++)
{
$result = mysql_query("SELECT * FROM dtable WHERE id=$i",$db);
$myrow = mysql_fetch_array($result);
$order[$i] = $myrow["rank"];
}

//Sort the array
sort($order, SORT_NUMERIC);

//Extract info from database using sorted results
for($i = 0; $i < 2; $i++)
{
$result = mysql_query("SELECT * FROM dtable WHERE rank=$order[$i]",$db);

//Put it in array form
$myrow = mysql_fetch_array($result);

//Place info in variables
$name = $myrow['name'];
$desc = $myrow['description'];
$adby = $myrow['adby'];
$rank = $myrow['rank'];
$id = $myrow['id'];


Now, it works pretty fine but I came upon a bug, if two entries have the same rank it reads one
entry twice! Ofcourse I figured out the problem but I dont know how to solve it, any suggestions?

08-07-2003 13:37 Send an Email to onzeponze Search for Posts by onzeponze Add onzeponze to your Buddy List
Telos Telos is a Male
Super Moderator


Registration Date: 06-04-2003
Posts: 130
Location: Finland
Linux Distro: hmm....

Rating:
3 Votes - Average Rating: 7.00

Level: 19 [?]
Experience Points: 18.489
Next Level: 22.851
4.362 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

I don't quite get the idea behind that but could DISTINCT solve your problems? like SELECT DISTINCT rank ...
with DISTINCT it gets only different values and not twice the sames.



08-07-2003 14:23 Send an Email to Telos Homepage of Telos Search for Posts by Telos Add Telos to your Buddy List Add Telos to your Contact List AIM Screenname: dreamimpactcom
onzeponze onzeponze is a Male
Lord


Registration Date: 06-17-2003
Posts: 384
Location: India
Linux Distro: Knoppix

Rating:
6 Votes - Average Rating: 3.83

Level: 23 [?]
Experience Points: 49.557
Next Level: 62.494
12.937 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

cool, i'll try it out

thanks

08-07-2003 15:22 Send an Email to onzeponze Search for Posts by onzeponze Add onzeponze to your Buddy List
onzeponze onzeponze is a Male
Lord


Registration Date: 06-17-2003
Posts: 384
Location: India
Linux Distro: Knoppix

Rating:
6 Votes - Average Rating: 3.83

Level: 23 [?]
Experience Points: 49.557
Next Level: 62.494
12.937 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

damn, it doesnt work!

08-08-2003 09:57 Send an Email to onzeponze Search for Posts by onzeponze Add onzeponze to your Buddy List
Post Reply:
Title (Optional):
Message:


Convert URLs: Automatically converts internet addresses into links by adding [url] and [/url] around them.
Email Notification: Notifies you by email every time there is a new post in this thread.
Deactivate smilies in this post.
Add Signature: Displays your signature in this post.


Tree Structure | Board Structure
Post New Thread Post Reply
Go to:


Powered by Burning Board 2.0.2 © 2001-2002 WoltLab GbR
English Translation by Satelk