PDA

View Full Version : little guidance


ali_b
04-30-2007, 02:58 PM
I have sort of combind two tutorials you have done, Here is the code:


<?php
require_once("connections/connection.php"); //database connection
$town = $_POST['town'];
if($town) {
/////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM shops where shop_id='$town'");
$result = @mysql_query($query);
$rowShop = @mysql_fetch_array($result);
////////////////////////////////////////////////////
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<select name="town" onChange="document.forms[0].submit()">
<option value="" selected>Select Your Town</option>
<option value="1" <?php if(!(strcmp(1, $town))){echo "selected";}?>>North Berwick</option>
<option value="2" <?php if(!(strcmp(2, $town))){echo "selected";}?>>Drem</option>
<option value="3" <?php if(!(strcmp(3, $town))){echo "selected";}?>>Gullane</option>
<option value="4" <?php if(!(strcmp(4, $town))){echo "selected";}?>>Aberlady</option>
</select>
</form>
<table>
<tr>
<td>Shop</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $rowShop['shop']?></td>
</tr>
<?php } while ($rowShop = @mysql_fetch_array($result)); ?>
</table>
</body>
</html>


I think i am going to have to change it a bit for what i want it to do next. I want to add another column with a link, when the user click the link it will open a new window displaying info about that shop.

dont really know where to go, so a little guidance would be great :D,

cheers,

Ali

davidj
04-30-2007, 03:28 PM
in your shop table just create an shop_info field. Make it a BLOB type (this will accept lots of text)

add some test data

where you have ...

<td><?php echo $rowShop['shop']?></td>

add this addition below it...


<td><?php echo $rowShop['shop']?></td>
<td><?php echo $rowShop['shop_info']?></td>

ali_b
04-30-2007, 03:59 PM
cool, cheers, would i be able to make the page that pops ups look good aswell?

an example of this would be:

http://booking.visitscotland.com/vs/scout/objectsearch/eat,en,SCH1,1319/waitCount,1/result.html;jsessionid=0a02028340765297d10d663444a 6a56cb0f2465be2e3.e38Mc30ObhaRc40LahuKb3aObx4Ke6fz nA5Pp7ftolbGmkTy?rls_chd=false&cla=&allsort=objname_a&langId=en&objectId=RGN20at&sbe=0&objname=&curr=EUR&SortListTop=SortListTop&catsel=&jse=1&objt=CTR&r=RGN20vs&selectedEntry=catering&mf2=&rls=&mf1=&season=at1&searchType=CTR&search.x=48&startRegion=Scotland&ralt=RGN560vs&allsorttop=objname_a&search.y=17&specsearchtype=CTR

when you click on more details it comes up with a new page with the same sort of theme going on, would this be possible?

basically i want it to open a new fully functional webpage that has tabs etc, like the example above. tell me if you dont understand. cheers

davidj
05-02-2007, 10:36 AM
Ok

the link below will open a popup window (notice the dimension values which you can change)

i am passing in the shop ID on the end of the page call. Try running the page to see the php render the IDs

To catch the ID you need to perform a $_GET['shop'] in the new page

also you need to have a query setup to run the SQL and the ID your passing into it

<a href="#" onclick="window.open('yourpage.php?shop=<?php echo $rowShop['shop']?>','shopwindow','location=1,status=1,scrollbars=1,w idth=100,height=100')" ><?php echo $rowShop['shop']?></a>

ali_b
05-02-2007, 10:40 AM
ye see this is why i think i have to change it. the shop id isnt an auto increment, what ive done is ive put the id of the shop to 1 if it is in north berwick etc etc, this means that if i pass that i cant give info on a specific shop in an area... hope this makes sense,

could you please give me a little help of what i should do, cheeers

davidj
05-02-2007, 10:47 AM
create a new db field and set it as an Auto increment

then use that

davidj
05-02-2007, 10:53 AM
isnt berwick still at war with russia?

ali_b
05-02-2007, 12:02 PM
loooool no! cheers for ur help, i changed some stuff in the database and i think i have it working.

i have never done the get thing before could you please sort of explain it to me, or tell me what i have to write.

here is my code so far:

<?php
require_once("connections/connection.php"); //database connection
$town = $_POST['town'];
if($town) {
/////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM shops where town_id='$town'");
$result = @mysql_query($query);
$rowShop = @mysql_fetch_array($result);
////////////////////////////////////////////////////
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<select name="town" onChange="document.forms[0].submit()">
<option value="" selected>Select Your Town</option>
<option value="1" <?php if(!(strcmp(1, $town))){echo "selected";}?>>North Berwick</option>
<option value="2" <?php if(!(strcmp(2, $town))){echo "selected";}?>>Drem</option>
<option value="3" <?php if(!(strcmp(3, $town))){echo "selected";}?>>Gullane</option>
<option value="4" <?php if(!(strcmp(4, $town))){echo "selected";}?>>Aberlady</option>
</select>
</form>
<table>
<tr>
<td>Shop</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $rowShop['shop']?></td>
<td><a href="#" onclick="window.open('yourpage.php?shop=<?php echo $rowShop['shop_id']?>','shopwindow','location=1,status=1,scrollbars=1,w idth=500,height=500')" >more info</a>
</td>
</tr>
<?php } while ($rowShop = @mysql_fetch_array($result)); ?>
</table>
</body>
</html>

davidj
05-02-2007, 12:37 PM
you have to create a new page

call that page shop_detail.php

in shop detail add above the html


<?php
require_once("connections/connection.php"); //database connection

$shop_id= $_GET['shop_id']; // << $_GET *********

if($shop_id) {
/////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM shops where town_id='$shop_id");
$result = @mysql_query($query);
$rowShop = @mysql_fetch_array($result);
////////////////////////////////////////////////////
}
?>


then in the new page just call the shop info variable.

davidj
05-02-2007, 12:39 PM
then you call the new page into a popup by doing this...

<a href="#" onclick="window.open('shop_info.php?shop=<?php echo $rowShop['shop_id']?>','shopwindow','location=1,status=1,scrollbars=1,w idth=500,height=500')" >

ali_b
05-02-2007, 12:43 PM
then you call the new page into a popup by doing this...

<a href="#" onclick="window.open('shop_info.php?shop=<?php echo $rowShop['shop_id']?>','shopwindow','location=1,status=1,scrollbars=1,w idth=500,height=500')" >


so this should be shop_info.php even though the other page is called shop_details.php

i dont understand how this page will change when i click on a different shop :(

davidj
05-02-2007, 12:54 PM
the page wont change. the data will

ok your popup can be called anything you want

shop_info.php
shop_details.php

in the popup you will have a SQL query but you need to pass an ID to get the right details for the shop you clicked

code in your popup...
<?php
require_once("connections/connection.php"); //database connection

$shop_id= $_GET['shop_id']; // << $_GET *********

if($shop_id) {
/////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM shops where town_id='$shop_id");
$result = @mysql_query($query);
$rowShop = @mysql_fetch_array($result);
////////////////////////////////////////////////////
}
?>

ok

notice the $_GET which we are using as a method to catch the value

we use $_GET because we are passing it through a querystring rather than a $_POST as you would in a form

do you understand this?

ali_b
05-02-2007, 12:57 PM
yes i think so, so do i have to put the info in the database or something :S

oh dear, i think im being really stuupiid! :(

davidj
05-02-2007, 01:02 PM
in your shop table you need a new field which holds the info

you are all ready calling the shop table data from your first code you posted and you could add the data to that page if you wanted just by echoing the new database shop_data field. But you want the data displayed in a popup window so you just have to pas the same ID into the popup window and let another query return the result so you are querying the same table twice really

ali_b
05-02-2007, 01:55 PM
ok thnk you, so should i make a new field and make it a blob ? if thats right how do i input data into that? on the other ones you just click 3 times but that doesnt work for taht.

ali_b
05-02-2007, 03:20 PM
here is what i have in the 1st page to link it to this page.

<a href="#" onclick="window.open('shop_details.php?shop=<?php echo $rowShop['shop_id']?>','shopwindow','location=1,status=1,scrollbars=1,w idth=500,height=500')" >more info</a>

so i should have another php file called shop_details.php, this is the code i have in it so far..

<?php
require_once("connections/connection.php"); //database connection
$shop_id = $_GET['shop_id']; // << $_GET *********
if($shop_id) {
/////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM shops where town_id='$shop_id");
$result = @mysql_query($query);
$rowShop = @mysql_fetch_array($result);
////////////////////////////////////////////////////
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>


Im still stuck, i dont understand why you have put town_id='$shop_id[/FONT]

here is an image of my database:
128

i dont know what to put in the body tags to display the data, i thought about putting <?php echo $rowShop['shop_data']?>

but that doesnt work. If that is completely wrong can u point me in the right direction?

cheers.

davidj
05-02-2007, 03:27 PM
you are almost there

its the same as the other tutorial but instead of submiting the form to the same page you are passing the ID to the popup

the popup catches the ID as normal then the query runs displaying the info

davidj
05-02-2007, 03:31 PM
Im still stuck, i dont understand why you have put town_id='$shop_id


forget about this bit

ali_b
05-02-2007, 03:33 PM
forget about it as in get rid of it, change it or just leave it?

davidj
05-02-2007, 03:36 PM
wait...

you use that to query your database..

town_id='$shop_id'

So you still need it if you use it in your SQL

ali_b
05-02-2007, 03:39 PM
hmm town_id doesnt always equal shop id, shop_id is auto increment and town_id isnt i give town_id a number so that is is the same as the value submitted in the dropdown menu

davidj
05-02-2007, 03:41 PM
do yu understand what you have covered so far in the tutorials?

do you understand the concept?

if you understand what you have done then its exactly the same as you know except you are passing the ID from a link rather than a drop down box

you are catching it using a $_GET and then performing the query as normal

davidj
05-02-2007, 03:42 PM
you need to set an auto increment in that table as discussed before

then use that instead

ali_b
05-02-2007, 04:08 PM
yes i think i have understood the other tutorials, i do have a field which is auto increment, its called shop_id, i dont think the id is being passed properly.

davidj
05-02-2007, 04:18 PM
to debug the query just add an echo


/////////////////////////////////////////////////////
echo $query = sprintf("SELECT * FROM shops where town_id='$shop_id");
$result = @mysql_query($query);
$rowShop = @mysql_fetch_array($result);
////////////////////////////////////////////////////


now run the page and see what returns to the screen
you should get something like this...

SELECT * FROM shops where town_id='11" //<< or another numeric

If its empty like this...

SELECT * FROM shops where town_id='"

then the variable isnt getting passed correctly

in the link that opens the popup and passes the variable

<a href="#" onclick="window.open('shop_details.php?shop=<?php echo $rowShop['shop_id']?>','shopwindow','location=1,status=1,scrollbars=1,w idth=500,height=500')" >more info</a>

that example is using shop as a var name and is setting the value using $rowShop['shop_id']

change those to suit your task

remember that the $_GET var will need to be set with the var name to catch the value


$_GET['shop']

ali_b
05-02-2007, 04:26 PM
haha its been working all along, i changed the var on the link to shop_id and it still wouldnt work but then i noticed this $query = sprintf("SELECT * FROM shops where town_id='$shop_id");

there is a " ' " missing at the end of it!

now i just need to no how to enter data into a blob plaseasease

davidj
05-02-2007, 04:28 PM
just add it as text

it will handle text fine

ali_b
05-02-2007, 04:38 PM
ok cheers! 1st script finished and working !! :D :D:D:D

davidj
05-03-2007, 08:02 AM
let me know when you have finished your project so i can see it