0

I am trying to get data from a database. I have the following code for that:

mysql_select_db($database_tony, $tony);
$query_rsTony = "SELECT `tony feature`.`text` 
                   FROM `tony feature`";

$rsTony = mysql_query($query_rsTony, $tony)) ;
if ($rsTony) echo 'set';
else echo 'not set'; 
$row_rsTony = mysql_fetch_row($rsTony)); 
if ($row_rsTony) echo 'set';
else echo 'not set';
$totalRows_rsTony = mysql_num_rows($rsTony);
$text = $row_rsTony['text'];

I am getting the output:

set not set

EDIT I added the changes said below and I have the above output. I don't know why the mysql_fetch_row($rsTony) is not working -- any ideas?

3
  • Is the query returning any rows? What does $totalRows_rsTony tell you? Commented Jul 15, 2011 at 16:36
  • 2
    As a side, I would strong suggest a better database naming convention (i.e. no spaces) and encourage the use of curly braces for all control structure blocks (i.e. if/else). Commented Jul 15, 2011 at 16:38
  • Thank you. I'll implement that. But is there anything wrong with the syntax or logic? Commented Jul 15, 2011 at 16:47

2 Answers 2

3

You need to use result which returned by mysql_query as mysql_fetch_row parameter:

$rsTony = mysql_query($query_rsTony, $tony)) ;
if ($rsTony) echo 'set';
else echo 'not set';

UPDATE

$row_rsTony = mysql_fetch_row($rsTony)); 
if ($row_rsTony) echo 'set';
else echo 'not set';
//....

So, you final code should look like

$rsTony = mysql_query($query_rsTony, $tony)) ;
if ($rsTony) echo 'set';
else echo 'not set';
$row_rsTony = mysql_fetch_row($rsTony)); 
if ($row_rsTony) echo 'set';
else echo 'not set';
Sign up to request clarification or add additional context in comments.

11 Comments

I am using the result from mysql_query as a parameter in mysql_fetch_row.
But you set $rsTony on the top of your code. Then you execute a bunch of other queries, but don't change $rsTony, it is still a result of the very first query execution.
got it. thank you. but if I do if($row_rsTony) it returns false. Any idea what went wrong?
It's still the same problem, you need to add $row_rsTony = mysql_fetch_row($rsTony); instead of (if(mysql_fetch_row($rsTony)) echo "set";).
Did I do what you asked me to? I am sorry. the $row_rsTony is returning false.
|
0

Your query looks funny. Try this:

$query_rsTony = "SELECT text FROM feature";

2 Comments

His table name looks funny. The query is just fine.
the mysql_query works. I get the same result even if I make the change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.