Hi,

if i wanted to convert and echo all the database results of "Petrol", "Gas", "Electricity" how would i do it?

<?php

mysql_connect("localhost","root","") or die("Unable to connect to SQL server"); 
mysql_select_db("test") or die("Unable to SELECT DB"); /////dont need



$query="SELECT Petrol, Gas, Electricity FROM country WHERE Country= 'England'";
$result=mysql_query($query);


$row = mysql_fetch_assoc($result);
echo $row['Petrol']; 



?>

    Kindly post your code in phpbbcode tags.

    Anyway, so far you are able to print the result for "Petrol", right? Use the $row array for the other two.

    You should also read the PHP manual concerning [man]mysql_fetch_assoc/man.

    Finally, if you have the choice, you may want to switch to using the MySQLi extension or PDO extension, but it is probably not important right now for learning purposes.

      edit beat by laserlight ... again

        laserlight wrote:

        Kindly post your code in phpbbcode tags.

        Anyway, so far you are able to print the result for "Petrol", right? Use the $row array for the other two.

        You should also read the PHP manual concerning [man]mysql_fetch_assoc/man.

        Finally, if you have the choice, you may want to switch to using the MySQLi extension or PDO extension, but it is probably not important right now for learning purposes.

        This young lady is spitting help like a machine. Thanks dear. 😃

          Write a Reply...