Page 1 of 1

Need help - query results don't display

Posted: Sat Jun 24, 2006 12:52 am
by Sinemacula
I'm trying to get what I think should be a fairly simple display of query results, but I can't get it to work.

Here's my php with the mysql query:

Code: Select all

<?php
$link = mysql_connect('host', 'user', 'pass') or die('Could not connect: ' . mysql_error());
mysql_select_db('database') or die('Could not select database: ' . mysql_error());
$query = "SELECT CONCAT(t2.stored_questionnaire_ID, t1.questionnaire_name, t2.stored_questionnaire_date) AS Link FROM qst_questionnaires AS t1, qst_stored_questionnaires AS t2, mos_users AS t3 WHERE t1.questionnaire_ID = t2.questionnaire_ID AND t2.user_id = t3.id AND t3.username = 'username' ORDER BY t2.stored_questionnaire_date DESC";
$result = mysql_query($query) or die('Query failed: '.mysql_error());

while ($myrow = mysql_fetch_array($result)) {
   echo "<a href=\"http:www.domain.com/index2.php?option=com_feedback&sqid=".$myrow["t2.stored_questionnaire_ID"]."\">".$myrow["t1.questionnaire_name"]."</a>, completed on ".$myrow["t2.stored_questionnaire_date"]."<br /><br />";;
  
}
echo "end";

mysql_free_result($result);

mysql_close($link);
?>
What I'm getting is just the ", completed on" and "end" with no data. I know the query itself works fine, so I'm guessing it has to do with the echo statement -- the only thing I can think of is that maybe having the "." within the field name is causing a problem?

Any suggestions?

Thanks,
Scott

Edit: missed a "." in the php code...

Posted: Sat Jun 24, 2006 1:06 am
by feyd
Records come back with field names only, not tables, by default.

Posted: Sat Jun 24, 2006 1:10 am
by Sinemacula
Thanks feyd...

Okay, I think that means to remove the "t2." and "t1." from the "$myrow[...]" -- now, having done that, I'm still getting the same output.

Where else am I making a mistake?

Thanks,
Scott

Posted: Sat Jun 24, 2006 1:12 am
by feyd
Try looking at what $myrow has in it.

Posted: Sat Jun 24, 2006 1:27 am
by Sinemacula
I was about to give up when it hit me... so I've also changed the query (got rid of the CONCAT for now) - and it's almost working...

...now the first two values are working, so I've got a working url being displayed using the data, but the "stored_questionnaire_date" is coming up blank. Does it have to be treated differently because it's last?

Posted: Sat Jun 24, 2006 1:32 am
by feyd
Did you remove the "AS Link" part as well?

Posted: Sat Jun 24, 2006 1:39 am
by Sinemacula
:oops: It must be past my bedtime. :wink:

Thanks for your help!!

One more question - if I wanted to go back to using the CONCAT and AS Link and put the url in the query, e.g.:

Code: Select all

$query = SELECT CONCAT('<a href=http://www.domain.com/index2.php?option=com_feedback&sqid=', t2.stored_questionnaire_ID, '>', t1.questionnaire_name,'</a>', ' completed on ', t2.stored_questionnaire_date) AS Link FROM qst_questionnaires AS t1, qst_stored_questionnaires AS t2, mos_users AS t3 WHERE t1.questionnaire_ID = t2. questionnaire_ID AND t2.user_id = t3.id AND t3.username = 'username' ORDER BY t2.stored_questionnaire_date DESC;
how would I get the result to display all returned rows as a list?

I just tried using

Code: Select all

echo .$myrow["Link"]. "<br /><br />";
but it came up blank.

Posted: Sat Jun 24, 2006 1:44 am
by feyd
ignoring the parse error your echo would generate, where did you place it? You may want to check what's actually in $myrow by using var_dump().

Posted: Sat Jun 24, 2006 1:51 am
by Sinemacula
var_dump showed me that the correct data was there, and that "Link" was the correct fieldname, so I changed the echo statement and got the output I was looking for.

Thanks for all your help, feyd!

Scott