PHP Noob Question - Trying to "GET" info from Database
Moderator: General Moderators
PHP Noob Question - Trying to "GET" info from Database
Hi all PHP gods,
I've been messing around with the php on a friends site and on for a while. Things are probably done incorrectly, but it seems to be working. The one problem i'm having is when I pass data through the URL, I'm not able to import all the MYSQL information using one variable. I was able to get it to work using the "GET" function, but I have to pass all the variables through the URL, but that creates a massive url string.
can somebody help me understand how to properly fetch the rest of the row information using just 1 variable?
Thanks so much!
I've been messing around with the php on a friends site and on for a while. Things are probably done incorrectly, but it seems to be working. The one problem i'm having is when I pass data through the URL, I'm not able to import all the MYSQL information using one variable. I was able to get it to work using the "GET" function, but I have to pass all the variables through the URL, but that creates a massive url string.
can somebody help me understand how to properly fetch the rest of the row information using just 1 variable?
Thanks so much!
Re: PHP Noob Question - Trying to "GET" info from Database
I'm not quite clear on what it is you're trying to do. Given your references to GET, I'll assume you're submitting a form using the get method and then trying to insert said data into your database. Is that about right? If so, you can specify each element in the $_GET array when you're building your SQL query. For instance, say you have someurl.com/?name=Bob&age=34&somevar=1. You would then go on to build your query like:
Or have I completely misunderstood what you're asking?
Code: Select all
$sql = "INSERT INTO table
SET name = '{$_GET['name']}',
age = $_GET['age'],
somevar = '{$_GET['somevar']}'";Re: PHP Noob Question - Trying to "GET" info from Database
Thank you for the reply Celauran, and I apologize that i am not explaining correctly, and I maybe getting in over my head here...
What I am trying to do is something like this:
I have a page that pulls product information from the database and displays it. From there if someone is interested in more information about the product they click the link. That link contains ALL the product information from the database and creates an extremely long URl. (here is a short example)
mydomain. com/product.php?description=You%20will%20love%20this%20amazing%20product.&price=211.87&id=100066024&size=xl&color=grey
What I am trying to do is just pass the product id and have the php script access the rest of the information from the product id to display on the product page.
mydomain. com/product.php?id=100066024
Does that make more sense?
What I am trying to do is something like this:
I have a page that pulls product information from the database and displays it. From there if someone is interested in more information about the product they click the link. That link contains ALL the product information from the database and creates an extremely long URl. (here is a short example)
mydomain. com/product.php?description=You%20will%20love%20this%20amazing%20product.&price=211.87&id=100066024&size=xl&color=grey
What I am trying to do is just pass the product id and have the php script access the rest of the information from the product id to display on the product page.
mydomain. com/product.php?id=100066024
Does that make more sense?
Re: PHP Noob Question - Trying to "GET" info from Database
Code: Select all
$sql = "SELECT * FROM products WHERE id = " . $_GET['id']Re: PHP Noob Question - Trying to "GET" info from Database
Indeed.s992 wrote:Code: Select all
$sql = "SELECT * FROM products WHERE id = " . $_GET['id']
Code: Select all
if (empty($_GET['id'])
{
$sql = "SELECT id FROM table";
}
else
{
$sql = "SELECT * FROM table WHERE id = $_GET['id']";
}Re: PHP Noob Question - Trying to "GET" info from Database
You are AWESOME
I has previously tried that, but I think I left the "$" out of the $_GET... PHP, so complicated yet so simple!
Okay last question, i can't seem to get it to import the info still, but I'm not getting any errors. On the previous we had used $style[$j] to call the information from that data base, but it doesn't seem to be working on this product page. Any ideas.
( The database select code has been changed to $sql="SELECT * FROM products where Product Number='$_GET[id]' "; )
I has previously tried that, but I think I left the "$" out of the $_GET... PHP, so complicated yet so simple!
Okay last question, i can't seem to get it to import the info still, but I'm not getting any errors. On the previous we had used $style[$j] to call the information from that data base, but it doesn't seem to be working on this product page. Any ideas.
( The database select code has been changed to $sql="SELECT * FROM products where Product Number='$_GET[id]' "; )
Re: PHP Noob Question - Trying to "GET" info from Database
Can we see your code?
Re: PHP Noob Question - Trying to "GET" info from Database
Code: Select all
$sql="SELECT * FROM product where Product Number='$_GET[id]' ";
$Type=array();
$Price=array();
$Color=array();
$Size=array();
$ID=array();
$PhotoLocation=array();
$result1=mysql_query($sql,$con);
if(!$result1)
{
echo "Bad";
}
else
{
while($row1=mysql_fetch_array($result1))
{
$counter=1;
$images=array();
$Type[]=$row1['type'];
$Price[]=$row1['price'];
$Color[]=$row1['color'];
$Size[]=$row1['size'];
$ID[]=$row1['id'];
$image=$row1['Photo Location'];
$images=explode(",",$image);
$PhotoLocation[]=$row1['Photo Location'];
$counter++;
unset($images);
}
mysql_close($con);
echo "</table>";
} ?>
Last edited by sdaztec on Sat Nov 27, 2010 2:57 pm, edited 2 times in total.
Re: PHP Noob Question - Trying to "GET" info from Database
You're missing an open quote here:
There's nothing happening in this loop:
And you don't have a variable named $Style.
Code: Select all
$Type[]=$row1[type'];Code: Select all
for($i=0;$i<sizeof($images);$i++)
{
}$PhotoLocation[]=$row1['Photo Location'];