Hi,

I am having a parse error with the codes below but my eyes just cant seem to find anything wrong. Hope somebody out there can help me.

<html>
<head>
<title>Using mysql_num_rows()</title>
</head>
<body>
<?php
$user = "";
$pass = "";
$db = "";
$link =  mysql_connect( "localhost", $user, $pass );

if ( ! $link ) {
    die( "Couldn't connect to MySQL" );
}

mysql_select_db( $db, $link ) or die ( "Couldn't open $db: ".mysql_error() );

$theacacaname=mysql_query("SELECT NAME FROM cgpa WHERE NAME = 'vanie'");

while ($row=mysql_fetch_assoc($theacacaname))
{
	echo "NAME: {$row['NAME']}";
}


$result = mysql_query("SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX FROM cgpa,cgpa1 WHERE cgpa1.NAME = '$theacacaname' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.RESULTS=cgpa1.RESULTS AND cgpa.MATRIX=cgpa1.MATRIX;";);

$num_rows = mysql_num_rows( $result );


while ($row=mysql_fetch_assoc($result))
{
	echo "MATRIX: {$row['MATRIX']}";
}

mysql_free_result($result);
mysql_free_result($theacacaname);
?>

:)

you can't use

<title>Using mysql_num_rows()</title>

i think i will be like

<title><?php mysql_num_rows() ?></title>

but why you want to use mysql_num_rows() in title?

Hi NAVI17,

Thanx. But it doesnt work. The parse error is in line 26. The sql query that is assigned to the variable $result is giving the error. If I comment it out than there is no parse error.

Can you see anything else that is wrong with my code??

-vanie-

i think there is a semicolon problem

$result = mysql_query("SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX FROM cgpa,cgpa1 WHERE cgpa1.NAME = '$theacacaname' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.RESULTS=cgpa1.RESULTS AND cgpa.MATRIX=cgpa1.MATRIX;";);

try this:

$result = mysql_query("SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX FROM cgpa,cgpa1 WHERE cgpa1.NAME = '$theacacaname' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.RESULTS=cgpa1.RESULTS AND cgpa.MATRIX=cgpa1.MATRIX");

if it still does not work then you should try this query in phpmyadmin.

i hope it helps.

Oh my goodness....Thanx alot...The irratating error is finally gone, but the query does not return a result if I use the variable $theacacaname but if i substitute with a name from the database it works.

example :

$theacacaname=mysql_query("SELECT NAME FROM cgpa WHERE NAME = 'mei yen'");


$result = mysql_query(SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX FROM cgpa,cgpa1 WHERE cgpa1.NAME = '$theacacaname' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.RESULTS=cgpa1.RESULTS AND cgpa.MATRIX=cgpa1.MATRIX");

The result is totally blank but if I do it like this then it works

$result = mysql_query(SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX FROM cgpa,cgpa1 WHERE cgpa1.NAME = 'mei yen' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.RESULTS=cgpa1.RESULTS AND cgpa.MATRIX=cgpa1.MATRIX");

Any idea why this is happening? I echoed the variable $theacacaname and it works....Thanx again for the help NAVI17

$theacacaname=mysql_query("SELECT NAME FROM cgpa WHERE NAME = 'mei yen'");

i think you are fetching the value from database.

you should write as:
$result=mysql_fetch_assoc($theacacaname);

now try with the variable $result..

i hope it works.

Hey NAVI17, it does not work :( What I am actually trying to do is store the name of the person in this case in the variable $theacacaname. I want to compare a row in two tables according to the name, in other words $theacacaname. Its kinda very difficult to explain in words but I hope you understand what I am trying to say. :)

Now my codes, does not display anything. No error, no result....sigh...

<html>
<head>
<title></title>
</head>
<body>
<?php
$user = "root";
$pass = "";
$db = "spps";
$link =  mysql_connect( "localhost", $user, $pass );

if ( ! $link ) {
    die( "Couldn't connect to MySQL" );
}

mysql_select_db( $db, $link ) or die ( "Couldn't open $db: ".mysql_error() );

$theacacaname=mysql_query("SELECT NAME FROM cgpa WHERE NAME = 'mei yen'");


/*while ($row=mysql_fetch_assoc($theacacaname))
{
	echo "NAME: {$row['NAME']}";
}*/

$thename=mysql_fetch_assoc($theacacaname);

$result = mysql_query("SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX FROM cgpa,cgpa1 WHERE cgpa1.NAME = '$thename' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.MATRIX=cgpa1.MATRIX");

//echo $result;

//$num_rows = mysql_num_rows( $result );


while ($row=mysql_fetch_assoc($result))
{
	echo "MATRIX: {$row['MATRIX']}";
}

mysql_free_result($result);
mysql_free_result($theacacaname); 
?>

What I am doing wrong here??

i think the problem is with this statement.

$result = mysql_query("SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX FROM cgpa,cgpa1 WHERE cgpa1.NAME = '$thename' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.MATRIX=cgpa1.MATRIX");

you should write it as:

$result = mysql_query("SELECT cgpa.NAME, cgpa.STATUS, cgpa.RESULTS, cgpa.MATRIX,cgpa1.NAME,cgpa1.STATUS,cgpa1.MATRIX  FROM cgpa,cgpa1 WHERE cgpa1.NAME = '$thename' AND cgpa.STATUS=cgpa1.STATUS AND cgpa.MATRIX=cgpa1.MATRIX");

now have a try. and do tell me its working or not?

This article has been dead for over six months. Start a new discussion instead.