1,105,450 Community Members

php mysql query wont work properly

Member Avatar
garyjohnson
Junior Poster
168 posts since Aug 2012
Reputation Points: 14 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

This code is suppose to take the images array and use its value for the name of the table. When I echo the images varaible I get kids, which is what $images[3] is set to equal, but when I put it in the query the $result2 is echoed as resource id #4. Why is it doing that?

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

mysql_select_db("photos", $con);

    echo $images[3];
    $query2="SELECT Location FROM $images[3] WHERE Pic_id='1'";
    $result2 = mysql_query($query2) or die(mysql_error());

echo $result2;

mysql_close($con);


?>
Member Avatar
TonyG_cyprus
Posting Whiz
329 posts since Dec 2009
Reputation Points: 36 [?]
Q&As Helped to Solve: 47 [?]
Skill Endorsements: 2 [?]
 
0
 

looks like you are trying to query an array, not a database table,
change '$images[3]' for the actual table name and try it.

LastMitch
Deleted Member
 
0
 

@garyjohnson

When I echo the images varaible I get kids, which is what $images[3] is set to equal, but when I put it in the query the $result2 is echoed as resource id #4. Why is it doing that?

I think you really need to learn how a query works. Right now, you are lost. I help you a few occasions and I notice you don't understand how to connect to the db and also understand how to create a query plus I also mention you need to touch up with the MYSQL.

Like what TonyG_cyprus mention

You can't fetch Location from an $images[3]? Is Location a column? Is $images[3] a table?

$query2="SELECT Location FROM $images[3] WHERE Pic_id='1'";

Read this:

http://www.w3schools.com/sql/default.asp

Member Avatar
AARTI SHRIVAS
Posting Pro in Training
410 posts since Dec 2012
Reputation Points: 2 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 3 [?]
 
0
 
$query2="SELECT Location FROM $images[3] WHERE Pic_id='1'"; 

instead of this use something like 
    $query2="SELECT `Location` FROM `column name` WHERE `Pic_id`=1";
    if u want ot delete 3 number image then pass pic_id=3
    do not use singal or double quotes for numbers in query
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: