Hi,
what i'm really trying to find out is how to run 2 queries and get the result of them in a single file.
The code goes Below, the problem is that the printed result comes only from the first query the second query result is displayed as 1st query result.
How can i avoid that?
Thank you.
Ian Heart

<?php
include("connection.php");

$result=mysql_query("SELECT *FROM curso where curso_name='Direito'");


$num=mysql_numrows($result);


$i=0;
while ($row=mysql_fetch_array($result)) 
{


$curso_name=mysql_result($result,$i,"curso_name");
$curso_periodo=mysql_result($result,$i,"curso_periodo");
$curso_disciplina1=mysql_result($result,$i,"curso_disciplina1");
$curso_disciplina2=mysql_result($result,$i,"curso_disciplina2");
$curso_disciplina3=mysql_result($result,$i,"curso_disciplina3");
$curso_preco=mysql_result($result,$i,"curso_preco");
	
}
echo $curso_name;
echo $curso_disciplina1;

//second query
$resultnumber=mysql_query("SELECT *FROM curso where curso_name='informatica'");
$num_second=mysql_numrows($resultnumber);


$x=0;
while ($row=mysql_fetch_array($resultnumber2)) 
{


$curso_name=mysql_result($resultnumber2,$x,"curso_name");
$curso_periodo=mysql_result($resultnumber2,$x,"curso_periodo");
$curso_disciplina1=mysql_result($resultnumber2,$x,"curso_disciplina1");
$curso_disciplina2=mysql_result($resultnumber2,$x,"curso_disciplina2");
$curso_disciplina3=mysql_result($resultnumber2,$x,"curso_disciplina3");
$curso_preco=mysql_result($resultnumber2,$x,"curso_preco");
	
}
echo $curso_name;
echo $curso_disciplina1;
?>
Member Avatar for rajarajan2017

May be it is the same result.

$resultnumber=mysql_query("SELECT *FROM curso where curso_name='informatica'");
echo $resultnumber;

From browser copy the echo result and execute it in your sql editor to see what you have as a result.

<?php
include("connection.php");

//second query
$resultnumber=mysql_query("SELECT *FROM curso where curso_name='informatica'");
$num_second=mysql_numrows($resultnumber);


$x=0;
while ($row=mysql_fetch_array($resultnumber2)) 
{


$curso_name=mysql_result($resultnumber2,$x,"curso_name");
$curso_periodo=mysql_result($resultnumber2,$x,"curso_periodo");
$curso_disciplina1=mysql_result($resultnumber2,$x,"curso_disciplina1");
$curso_disciplina2=mysql_result($resultnumber2,$x,"curso_disciplina2");
$curso_disciplina3=mysql_result($resultnumber2,$x,"curso_disciplina3");
$curso_preco=mysql_result($resultnumber2,$x,"curso_preco");
	
}
echo $curso_name;
echo $curso_disciplina1;
?>

First query found fine.in second query from where $resultnumber2 is coming
If I am not wrong I think it should be $resultnumber.
Please check it.If you have any query let me know.


One suggestion for retrieving or fetching data from mysql.
Please refer this link for this
http://www.w3schools.com/php/php_mysql_select.asp

Thanks.

Thank You Baiyaa!

The correct code would be

<?php
include("connection.php");

$result=mysql_query("SELECT *FROM curse where curse_name='law'");
echo $result;

$num=mysql_numrows($result);


$i=0;
while ($row=mysql_fetch_array($result)) 
{


$curso_name=mysql_result($result,$i,"curso_name");
$curso_periodo=mysql_result($result,$i,"curso_periodo");
$curso_disciplina1=mysql_result($result,$i,"curso_disciplina1");
$curso_disciplina2=mysql_result($result,$i,"curso_disciplina2");
$curso_disciplina3=mysql_result($result,$i,"curso_disciplina3");
$curso_preco=mysql_result($result,$i,"curso_preco");
	
}
echo $curso_name;
echo $curso_disciplina1;

//second query
$resultnumber=mysql_query("SELECT *FROM curso where curso_name='informatica'");
$num_second=mysql_numrows($resultnumber);
echo $resultnumber;

$x=0;
while ($row=mysql_fetch_array($resultnumber)) 
{


$curso_name=mysql_result($resultnumber,$x,"curso_name");
$curso_periodo=mysql_result($resultnumber,$x,"curso_periodo");
$curso_disciplina1=mysql_result($resultnumber,$x,"curso_disciplina1");
$curso_disciplina2=mysql_result($resultnumber,$x,"curso_disciplina2");
$curso_disciplina3=mysql_result($resultnumber,$x,"curso_disciplina3");
$curso_preco=mysql_result($resultnumber,$x,"curso_preco");
	
}
echo $curso_name;
echo $curso_disciplina1;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.