[Solved] Custom PHP w/ SQL query.

status260 01 Feb, 2012
Could someone please help me with this. I'm not getting an error message only a blank page.

Shouldn't this be displaying every row in column fullName?

<?php

mysql_connect("host", "username", "password") or die(mysql_error("Could not connect to server."));
mysql_select_db("databasename") or die(mysql_error("Could not select database."));

	

$query="SELECT * FROM `tablename`";


  
$result= mysql_query($query) or die(mysql_error("Could not process query.")); 
    
	
	while($row=mysql_fetch_array($result) or die(mysql_error("Could not display results."))
    {
    echo "Name:".$row['fullName'];
     
    }


?>
GreyHead 01 Feb, 2012
Hi status260,

Rewritten in Joomla! code
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT *
        FROM `#__tablename`;
";
$db->setQuery($query);
$data = $db->loadAssocList();
foreach ( $data as $d ) {
  echo 'Name: '.$d['fullName'];
}
?>


Bob
status260 01 Feb, 2012
I know I posted in the Joomla forum but I'm using PHP outside of Joomla.
status260 09 Feb, 2012
 while($row=mysql_fetch_array($result) or die(mysql_error("Could not display results."))
{
echo "Name:".$row['fullName'];
}



should be

  while($row=mysql_fetch_array($result)
  {
        $fullName = $row['fullName'];

    echo "$fullName";
  }


The $result variable is already checking for an error.
This topic is locked and no more replies can be posted.