rendering query x times instead of required once because instance... help?
I am trying to return a custom query, which renders each row once, however sometimes the table it queries is the same... For example. My output code currently is this...
//Query one returns each instance of an object. There are two of the first, one of the second.
13775
13775
66777
//Query two returns each bit of information against the first object.
// As you can see its loading the first too twice because of the query above being the same...
SID=13775 TOKEN=b8r5x6w53d6cahw
SID=13775 TOKEN=p5ugbeg68b4qixy
SID=13775 TOKEN=b8r5x6w53d6cahw
SID=13775 TOKEN=p5ugbeg68b4qixy
SID=66777 TOKEN=4c85zznh955gjsc
My code is as follows for the above display...
//Query table where firstname, lastname and email all match
$query = "SELECT * FROM lime_all_tokens WHERE fname='".$fname."' AND lname ='".$lname."'";
//execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$sid = array();
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after ano开发者_JAVA百科ther
$i = 0;
while($row = mysql_fetch_row($result)) {
//Shows the SID's
echo $row[5]."<br />";
//Add into the DB in order...
$sid[] = $row[5];
$i++;
}
}
// free result set memory
mysql_free_result($result);
for ($j = 0; $j < $i; $j++) {
$querytokens = "SELECT * FROM lime_tokens_".$sid[$j]." WHERE firstname='".$fname."' AND lastname ='".$lname."'";
echo $tokens[$j]."<br />";
//execute query
$resulttokens = mysql_query($querytokens) or die ("Error in query: $querytokens. ".mysql_error());
// see if any rows were returned
//print_r(mysql_fetch_row($resulttokens));
while($rowtokens = mysql_fetch_row($resulttokens)) {
//Display our token
echo "SID=".$sid[$j]." TOKEN=".$rowtokens[5]."<br />";
$displayonce = false;
}
}
echo "<br /><br /><h2>There are a total of ".$i." calls availible!</h2>";
// free result set memory
mysql_free_result($resulttokens);
// close connection
mysql_close($connection);
How can i get it to return the data properly? i.e
13775
13775
66777
SID=13775 TOKEN=b8r5x6w53d6cahw
SID=13775 TOKEN=p5ugbeg68b4qixy
SID=66777 TOKEN=4c85zznh955gjsc
IMHO you could change first query to:
SELECT DISTINCT id
FROM lime_all_tokens
WHERE fname='".$fname."' AND lname ='".$lname."'"
精彩评论