Jump to content

Array help


CageyJ0nnY

Recommended Posts

I have created an array to store data extracted from a dedicated database. I cannot get the code to work and keep geeting an error on line 9; however i cannot see what the error is 8-S.

 

Heres the code:

 

<?php

$conn = mysql_connect('jjennings3db.bimserver2.com', 'jjennings3db', 'bullet234345');

mysql_select_db(“jjennings3db”, $conn);

 

$sql = "SELECT * FROM tblProperties WHERE xxx=xxx";

echo "Here are all the properties that match your search:<br>";

 

$result1 = mysql_query($sql, $conn);

while ($array1 = mysql_fetch_array($result1)) {

echo "<p>Property Name: " . $array1[PropertyName] . "<br>";

echo "Location: " . $array1[Location] . "</p>";

}

?>

 

p.s I have changed log on details

 

many thanks

 

Jonny

Link to comment
https://forums.phpfreaks.com/topic/202015-array-help/
Share on other sites

You should always check your queries actually execute successfully and return results before trying to use them.

 

$sql = "SELECT * FROM tblProperties WHERE xxx=xxx";
echo "Here are all the properties that match your search:<br>";

if ($result1 = mysql_query($sql, $conn)) {
  if (mysql_num_rows($result1)) {
    while ($array1 = mysql_fetch_array($result1)) {
      echo "<p>Property Name: " . $array1['PropertyName'] . "<br>";
      echo "Location: " . $array1['Location'] . "</p>";
    }
  } else {
    echo "No results found";
  }
} else {
  trigger_error(mysql_error() . "<br />" . $sql);
}

 

Now, what error are you getting?

?>

Link to comment
https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059391
Share on other sites

I have inserted the new code and connected to the DB. I am getting a new error message:

 

Notice: No database selected

SELECT * FROM tblProperties WHERE xxx=xxx in /home/jjennings3/jjennings3.bimserver2.com/search.php on line 19

 

line 19 is :

 

trigger_error(mysql_error() . "<br />" . $sql);

 

 

I am confused 8-S

 

thanks for the help

Link to comment
https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059395
Share on other sites

okay, i have sorted some things out but i have a new error message:

 

 

Notice: Unknown column 'xxx' in 'where clause'

SELECT * FROM tblProperties WHERE xxx=xxx in /home/jjennings3/jjennings3.bimserver2.com/search.php on line 18

 

heres how the code looks at the moment:

 

<?php

$conn = mysql_connect('jjennings3db.bimserver2.com', 'jjennings3db', 'bullet3475783');

mysql_select_db('jjennings3db', $conn);

 

$sql = "SELECT * FROM tblProperties WHERE xxx=xxx";

echo "Here are all the properties that match your search:<br>";

 

if ($result1 = mysql_query($sql, $conn)) {

  if (mysql_num_rows($result1)) {

    while ($array1 = mysql_fetch_array($result1)) {

      echo "<p>Property Name: " . $array1['PropertyName'] . "<br>";

      echo "Location: " . $array1['Location'] . "</p>";

    }

  } else {

    echo "No results found";

  }

} else {

  trigger_error(mysql_error() . "<br />" . $sql);

}

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059430
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.