Go4Expert

Go4Expert (http://www.go4expert.com/)
-   PHP (http://www.go4expert.com/forums/php/)
-   -   Warning: mysql_fetch_array():?? (http://www.go4expert.com/forums/warning-mysqlfetcharray-t28389/)

faizdead 15May2012 17:59

Warning: mysql_fetch_array():??
 
this is my coding for php..i need it to extract information on my database.


PHP Code:

<HTML>
<HEAD><TITLE>List of Registrations</TITLE><HEAD>
<BODY>
<TABLE BORDER="1">
<tr>
<th>Semester</th>
<th>Subject name</th>
<th>Section</th>
<th>Name</th>
</tr>
<?php
mysql_connect
("---","---","---") or die("Connection Failed");
mysql_select_db("---")or die("Connection Failed");
$name $_POST['card'];

$result mysql_query("select s1.name, s2.subject_name, s3.semester,s4.section " .
"from Student as s1, pelajar as s2, student_subject s3"." where semester = '$name' and"."(s3.matric = s1.matric)
and "
.
" (s2.subject_code=s3.subject_code)");

while (
$line mysql_fetch_array($result))
{

echo 
"<TR align=left>\n";
echo 
"<TD>"$record["semester"], "</TD>",
"<TD>"$record["subject_name"], "</TD>",
"<TD>"$record["section"], "</TD>",
"<TD>"$record["name"], "</TD>";
echo 
"</TR>\n";
}
?>



</TABLE>
</BODY>
</HTML>





and this error keep coming..why is it?

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

pein87 29May2012 02:03

Re: Warning: mysql_fetch_array():??
 
Your query needs work, you need to first check to see if it returns anything using phpmyadmin or mysql workbench.

try this:



PHP Code:

$result mysql_query("SELECT s1.name, s2.subject_name, s3.semester,s4.section FROM Student as s1, pelajar as s2, student_subject s3 WHERE semester = '"$name ."' AND s3.matric = s1.matric
AND s2.subject_code = s3.subject_code"
); 

and see if it returns something by saying this:

PHP Code:

$rowFlag mysql_num_rows($result);

if(
$rowFlag <= 0)
{
 
// debug error here, no results returned.
}
else
{
// do output work


if that doesn't work try checking your query. Also no usernmae,password, or host is selected in the connect statement so your not connected to any resources and no database is selected either.

Alex.Gabriel 30May2012 01:07

Re: Warning: mysql_fetch_array():??
 
Where did you copy/paste this script ?
You have defined
Code:

$line
and queryed
Code:

$record
PHP Code:

<HTML>
<HEAD><TITLE>List of Registrations</TITLE><HEAD>
<BODY>
<TABLE BORDER="1">
<tr>
<th>Semester</th>
<th>Subject name</th>
<th>Section</th>
<th>Name</th>
</tr>
<?php
mysql_connect
("---","---","---") or die("Connection Failed");
mysql_select_db("---")or die("Connection Failed");
$name $_POST['card'];

$result mysql_query("select s1.name, s2.subject_name, s3.semester,s4.section " .
"from Student as s1, pelajar as s2, student_subject s3"." where semester = '$name' and"."(s3.matric = s1.matric)
and "
.
" (s2.subject_code=s3.subject_code)");

while (
$line mysql_fetch_array($result))
{

echo 
"<TR align=left>\n";
echo 
"<TD>"$line["semester"], "</TD>",
"<TD>"$line["subject_name"], "</TD>",
"<TD>"$line["section"], "</TD>",
"<TD>"$line["name"], "</TD>";
echo 
"</TR>\n";
}
?>



</TABLE>
</BODY>
</HTML>



All times are GMT +5.5. The time now is 20:09.