Jump to content

[SOLVED] where did i go wrong? New to PHP


ManOnScooter

Recommended Posts

I get just 1 value for the select query...

I just want to display the returned value

Where did i go wrong ??

 

<?php

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

if (!$con)

  {

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

  }

  mysql_select_db("test", $con);

  $result = mysql_query("SELECT details FROM test where first_name like "%Scooter%"");

  $row = mysql_fetch_row($result);

  echo $row;

  mysql_close($con);

?>

Link to comment
https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/
Share on other sites

if you just want everything from the details column with no search creteria just do

 

<?php

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

if (!$con)

  {

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

  }

  mysql_select_db("test", $con);

  $result = mysql_query("SELECT details FROM test);

  $row = mysql_fetch_row($result);

  echo $row;

  mysql_close($con);

?>

 

i think that will return everything from the details column. I am not sure as i cant test it as i am at work

adam, that dint work..

 

This one worked

 

<?php

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

if (!$con)

  {

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

  }

 

mysql_select_db("test", $con);

 

$result = mysql_query("SELECT details FROM test WHERE first_name LIKE '%scooter'");

 

while($row = mysql_fetch_array($result))

  {

 

  echo $row['details'];

 

  }

 

mysql_close($con);

?>

 

 

is there a way to do it without the while loop??

like i said i am new to this. I dont this you can do it without the while loop. This is because the while loop is saying that while there is information in the table to be displayed echo it. All tutorials i have looked at always have the while loop.

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.