...

View Full Version : Using parameters and query



feras_wilson
07-29-2007, 09:34 AM
Hej!

I have many pictures from a library to books so i need to create a query in PHP like this:

mybooks.php?showbook=1

Please help!:confused:

_Aerospace_Eng_
07-29-2007, 09:44 AM
Not sure what you asking. It sounds like you want to use the the showbook value inside of a mysql query. While I won't write the whole thing for you, this should get your started.

$showbook ='';
if(isset($_GET['showbook']) && $_GET['showbook'] != '')
{
$showbook = $_GET['showbook'];
}
$sql = "SELECT * FROM tablename WHERE bookid = $showbook";
$query = mysql_query($sql) or die('The mysql error is :' . mysql_error() .'<br>The query is: ' . $sql);
After the query runs you can use mysql_fetch_array to get what you want displayed. Be sure to change tablename to the correct name of the table in your database.

feras_wilson
07-29-2007, 09:53 AM
I mean that if i have a database ike this:


ID Picture Description
1 some1.jpg Its a new book
2 some2.jpg Its a future book
3 some3.jpg Its a old book
4 some4.jpg Its a history book


Then when i type in the adress bar: showbook.php?id=1
it will show the picture some1.jpg and the description of some1.jpg

_Aerospace_Eng_
07-29-2007, 09:57 AM
Right. What kind of database do you have? If its mysql then I gave you what you need to do it. I even told you what function to use to get the correct data.

feras_wilson
07-29-2007, 10:05 AM
Right. What kind of database do you have? If its mysql then I gave you what you need to do it. I even told you what function to use to get the correct data.
Ok, thanks but can you just give me the sql database name och the table name because i can't read the SQL

_Aerospace_Eng_
07-29-2007, 10:12 AM
I don't know that information. You should have set this information when you setup your database.

feras_wilson
07-29-2007, 10:15 AM
I don't know that information. You should have set this information when you setup your database.
Ok, thank you!:thumbsup: :thumbsup:

feras_wilson
07-29-2007, 10:35 AM
I get this error when i try:


The mysql error is :Access denied for user 'vhostswww'@'localhost' (using password: NO)
The query is: SELECT * FROM table2 WHERE bookid =

_Aerospace_Eng_
07-29-2007, 06:09 PM
Did you connect to the database? You need a username and password to connect to the database. You can use mysql_connect(). Then you will need to use mysql_select_db() to select the correct database.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum