View Full Version : displaying details
harlequin2k5
07-15-2006, 03:25 PM
so I have a summary list page and what I'd like to do is when you click on a particular vendor the rest of their information displays
<?php
$conn = doconnect();
$query = "SELECT `VendorName` FROM `tblVendorInfo` where VendorName LIKE 'A%'";
$result = mysql_query($query);
echo "<ul>\n";
while($row = mysql_fetch_assoc($result))
{
echo "<li><a href=\"#\">" . $row['VendorName'] . "</a></li>";
}
echo "</ul>\n";
mysql_free_result($result);
?>
VendorName is the link
I'm in the process of adding VendorID because there are a few vendors with the same name located in different parts of the state
and for what it's worth...PHP and MySQL For Dynamic Web Sites by Larry Ullman is a huuuuuuuuge disappointment :(
thanks in advance! :)
Brandoe85
07-15-2006, 09:01 PM
Hi,
So you do have vendorID in the table? Pass the vendorID to a page, and grab it with $_GET, then in your query, select fields from table where vendorID = $_GET['vendorID'].
// i like to use single quotes and concatenat on the variable you need...this way you can use double quotes for your html and not have all the escaping.
echo '<li><a href="somepage.php?vendorID=' . $row['vendorID'] . '">' . $row['VendorName'] . '</a></li>';
Now, you should have the link set up. Next, create somepage.php(or whatever you're going to call it) and do your query:
$id = (isset($_GET['vendorID'])) ? $_GET['vendorID'] : false;
if($id)
{
// vendor id was passed
$query = 'select fields from table where vendorID = ' . $id;
$result = mysql_query($query) or die(mysql_error()); // add mysql_error() for debugging.
while($row = mysql_fetch_assoc($result))
{
// display your info
}
}
Hopefully that'll help some.
Good luck;
ns1987
07-15-2006, 10:32 PM
Don't forget to protect your SQL by using intval(), typecasting or some other method on $id.
harlequin2k5
07-19-2006, 02:24 AM
ok I used your code sample and the subdetail.php comes up just fine except that it doesn't display any data - I've been at this a couple of hours now so I'm sure I'm just not seeing something real simple
<?php
$id = (isset($_GET['VendorID'])) ? $_GET['VendorID'] : false;
if($id)
{
// vendor id was passed
$query = 'SELECT VendorID, VendorName, VendorAddress1, VendorAddress2, VendorCity, VendorState, VendorZip, VendorPhone, VendorFax, VendorURL, VendorEmail from tblVendorInfo where VendorID =' . $id;
//select fields from table where VendorID = ' . $id;
$result = mysql_query($query) or die(mysql_error()); // add mysql_error() for debugging.
while($row = mysql_fetch_assoc($result))
{
// display your info
echo $row['VendorName'];
}
echo "</ul>\n";
} ?>
Don't forget to protect your SQL by using intval(), typecasting or some other method on $id.
I don't understand what you mean
Brandoe85
07-19-2006, 02:54 AM
Does it make it passed the if statement? Add this on:
<?php
$id = (isset($_GET['VendorID'])) ? $_GET['VendorID'] : false;
if($id)
{
echo 'The id is: ' . $id;
// vendor id was passed
$query = 'SELECT VendorID, VendorName, VendorAddress1, VendorAddress2, VendorCity, VendorState, VendorZip, VendorPhone, VendorFax, VendorURL, VendorEmail from tblVendorInfo where VendorID =' . $id;
//select fields from table where VendorID = ' . $id;
$result = mysql_query($query) or die(mysql_error()); // add mysql_error() for debugging.
while($row = mysql_fetch_assoc($result))
{
// display your info
echo $row['VendorName'];
}
echo "</ul>\n";
} ?>
harlequin2k5
07-19-2006, 03:13 AM
I tried that too...I'd show you a screen shot but I can't seem to figger out how *chuckles*
The address bar shows that it has selected vendorid 540 which is the vendorid for abbey carpet - but it doesn't show even the vendor name on the detail page
I think you can get to the page from here (http://67.78.185.42:1985/subinfo.php)
Brandoe85
07-19-2006, 03:19 AM
Heh, link doesn't work :(
But, did it display "The id is 540"? If not, make sure the querystring "VendorID" is the same case as the $_GET['VendorID']
Good luck :)
harlequin2k5
07-19-2006, 03:43 AM
the address bar displays...
http://67.78.185.42:1985/subdetail.php?vendorID=1459
I even added some dummy text after and that displays so I think it's at least passing the "if"
I checked to make sure I was using the proper case for everything and I am - I've gotten caught by that before
I tried adding the vendorid to the results echo and that didn't come up either - and yes there are details to be displayed - if only the vendor name - this data is taken from an existing database
Brandoe85
07-19-2006, 03:49 AM
Hmm..I see it's a small case v in the querystring and a capital V in the assignment...so, not sure what you have but make sure it's:
$id = (isset($_GET['vendorID'])) ? $_GET['vendorID'] : false;
Note the small v in vendorID. Can you verify that's what you have?
harlequin2k5
07-19-2006, 03:58 AM
when you had originally given me the code you wrote it as vendorID - I changed it to VendorID because that's the proper field name - should I change it back to the lowercase?
harlequin2k5
07-19-2006, 03:59 AM
before you answer that - it displays the id now and then says no database selected
Brandoe85
07-19-2006, 04:01 AM
Whichever you'd like. Just make sure they are the same case. Just make sure the URL:
http://67.78.185.42:1985/subdetail.php?vendorID=1459
Is the same as that statement:
$id = (isset($_GET['vendorID'])) ? $_GET['vendorID'] : false;
That should work, now..if you'd like them to be a capital V just make sure you change them in both places.
harlequin2k5
07-19-2006, 04:01 AM
ok so I'm a dope - I didn't have my connect() in there and changing it to lower case worked
I'm just curious why? if the field name is VendorID why wouldn't I look for it instead of vendorID?
harlequin2k5
07-19-2006, 04:02 AM
I got it - that makes perfect sense
I'll get what I ask for
thanks for your patience brandoe85!
Brandoe85
07-19-2006, 04:05 AM
The reason is because that's not the name from your DB...it's just a name we made up when we built the URL here:
echo '<li><a href="somepage.php?vendorID=' . $row['vendorID'] . '">' . $row['VendorName'] . '</a></li>';
So we have to make sure it's vendorID in $_GET. We could've named it harlequin2k5=55 :D
But now i'm just blabing on...i'm glad it works :)
harlequin2k5
07-19-2006, 04:30 AM
thanks brandoe85
but for your edification...harlequin2k5=37 :p
may I be so bold as to ask one more question? I can't seem to make a linebreak
I've tried "\n", \"n", \n, '\n', \'n' - it is currently "\n"
echo $row['VendorName'] . "\n" . $row['VendorAddress1'] . "\n" . $row['VendorAddress2'] . "\n" . $row['VendorCity'] . ", " . $row['VendorState'] . " " . $row['VendorZip'] . "\n" . $row['VendorEmail'] . "\n" . $row['VendorURL'];
does the line break have to go into its own echo?
Brandoe85
07-19-2006, 04:32 AM
I stand corrected! :p
"\n" will put a line feed in your source, so you can format your white space of the generated html. You'll want to use <br>.
Good luck;
harlequin2k5
07-19-2006, 04:36 AM
that's absolutely perfect!
I shoulda realized about the < br >
ok go to bed now - you've earned it :)
Brandoe85
07-19-2006, 04:42 AM
Great!
I didn't even know you guys got a chance to be on a computer in Florida...are you on the beach with your laptop? :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.