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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.