Jump to content

Mysql Select


forumnz

Recommended Posts

Please help - I am realy having trouble with this.

 

It comes up with error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/html/show_mid.php on line 12

 

Code:

<?php
$con = mysql_connect("localhost","aaa","aaa");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("photomagik_co_nz_-_soho", $con);

$result = mysql_query("SELECT * FROM show");

while($row = mysql_fetch_array($result))
  {
  echo $row['title'] . " " . $row['link'];
  echo "<br />";
  }

mysql_close($con);
?>

Thanks,

Sam.

Link to comment
https://forums.phpfreaks.com/topic/66610-mysql-select/
Share on other sites

Your not far wrong, but you should always do some error handling when dealing with a database. Try...

 

<?php

  if (!$con = mysql_connect("localhost","aaa","aaa")) {
    die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("photomagik_co_nz_-_soho", $con);

  $sql = "SELECT * FROM show";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_array($result)) {
        echo $row['title'] . " " . $row['link'] . "<br />";
      }
    } else {
      echo "No records found<br />";
    }
  } else {
    echo "Query failed<br />$sql<br />" . mysql_error();
  }

  mysql_close($con);

?>

 

What do you get now?

Link to comment
https://forums.phpfreaks.com/topic/66610-mysql-select/#findComment-333732
Share on other sites

in my machine ur code is  working without any error

 

check this

 

<?php

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("timesheet", $con);

 

$result = mysql_query("SELECT * FROM test1");

 

while($row = mysql_fetch_array($result))

  {

  echo $row['firstname'] . " " . $row['age'];

  echo "<br />";

  }

 

mysql_close($con);

?>

 

result is

 

tom  25

Link to comment
https://forums.phpfreaks.com/topic/66610-mysql-select/#findComment-333771
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.