Closed Thread Icon

Preserved Topic: hyperlink to php mysql dbase (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13077" title="Pages that link to Preserved Topic: hyperlink to php mysql dbase (Page 1 of 1)" rel="nofollow" >Preserved Topic: hyperlink to php mysql dbase <span class="small">(Page 1 of 1)</span>\

 
CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-06-2004 20:52

I've done this with a pull-down menu but never a hyperlink. How do I put this info that normally goes in a <form> tag? Maybe the wquestion is "can I query a dbase thru a hyperlink? or simply point the link to a column in my dbase or a separate table"

Scenario #1:

form method=post action="file:///C%7C/upload_planter/form_State2.php"
<select name="Company">


somehow fit into:

<a href="#">Link to all Dell coupons</a>

My table is set up like this:

ID Company Coupon
--- ----------- ----------
1 Apple www.applecoupon1.com
2 Dell www.dellcoupon2.com
3 Apple www.applecoupon2.com
4 Dell www.dellcoupon1.com

or . . . .


Scenario #2:

have the link simply point to the column or table

<a href="listMerchants.php?ID=296">coupon</a>


Is that what the above is doing?

[This message has been edited by CRO8 (edited 03-07-2004).]

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 03-07-2004 00:56

Yes, this is very possible. You simply have to have PHP grab the ID variable out of the GET array.

Customise this snippet of code into your page and see if it works:

code:
$query = "SELECT ID,description FROM coupons ORDER BY ID ASC";
$result = mysql_query($query);
$coupon_obj = $mysql_fetch_object($result);

while ($coupon_obj)
{
echo '<a href="listmerchants.php?ID='.$coupon_obj->ID.'">'.$coupon_obj->description.'</a><BR />";
}



That should query the database for your coupons and the descriptions, put them into an object and step through that object creating a hyperlink for each one.

Enjoy.

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-08-2004 00:08

hey thanks Skarjj- I put your code in and still trying to fiddle with it. Here is the page

The drop downs work fine but the hyper link still doesn?t work. Instead of ID=## I put ID=Dell which is what I want to search the table by so I tweaked it a bit . . .

<a href="Greg_Apple_2.php?ID=Dell">Dell</a>


//from skarjj ozoneasylum
$query = "SELECT Company FROM coupons ORDER BY ID ASC";
$result = mysql_query($query);
$coupon_obj = $mysql_fetch_object($result);
while ($coupon_obj){ echo '<a href="Greg_Apple_2.php?ID='.$coupon_obj->Company.'">'.$coupon_obj->Coupon.'</a><BR />";}



Am I on the right path?

Thanks!

[This message has been edited by CRO8 (edited 03-08-2004).]

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-08-2004 00:53

CRO8:

Are you looking for $_GET['ID'] in your Greg_Apple_2.php script?

Without being able to see the code your using it's kinda hard to try and decide what might be wrong. What are the differences between the script your using for the pull-downs and the script your using for the hyperlink?

-Butcher-

[This message has been edited by butcher (edited 03-08-2004).]

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-08-2004 01:39

Hi butcher

My drop downs and hyperlink are pointed to 2 different php files, I will show you the hyperlink code- only difference between the 2 php files is the code I inserted from skarjj.

Hyperlink php page

<!-- begin form-->
<?php

// connect to your mysql server
mysql_connect ("localhost","name","password")
or die("Could not connect: " . mysql_error());

// define the database you are going to use
mysql_select_db ("Greg_dbase");

//from skarjj ozoneasylum
$query = "SELECT Company FROM coupons ORDER BY ID ASC";
$result = mysql_query($query);
$coupon_obj = $mysql_fetch_object($result);
while ($coupon_obj){ echo '<a href="Greg_Apple_2.php?ID='.$coupon_obj->Company.'">'.$coupon_obj->Coupon.'</a><BR />";}


// define the Apple mysql query you want to run
$result = mysql_query ("SELECT Company,Coupon
FROM coupons
WHERE Company LIKE '".$Company."'");

// a count query to tell the user how many Apple results where found
$count = mysql_query ("SELECT COUNT(*)
FROM coupons
WHERE Company LIKE '".$Company."'");

// defines the State countresult so we can display it later
$countresult = mysql_fetch_array($count);

// prints the number of Apple results found
print "<center><font color=red><strong>".$countresult[0]."</strong></font> results found:<br><br></center>";

// simple loop to display all the Apple results in the array
if ($row = mysql_fetch_array($result)) {

do {
print '<a href="http://' . $row['Coupon'] . '"target=_blank>' . $row['Coupon'] . "</a><br>\n";


} while($row = mysql_fetch_array($result));

} else {print "<center>We apologize, at this present time we do not have a coupon for this company.</center>";}

//hiding this line
//echo "<hr noshade width=425 align=left>";
?>
<!-- end form-->

[This message has been edited by CRO8 (edited 03-08-2004).]

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-08-2004 02:37

I think the problem is here:

$result = mysql_query ("SELECT Company,Coupon
FROM coupons
WHERE Company LIKE '".$Company."'");


Your code is using $company but your hyperlink is sending $ID.

Either change your hyperlink to:

<a href="Greg_Apple_2.php?Company=Dell">Dell</a>

or change your code to:


$result = mysql_query ("SELECT Company,Coupon
FROM coupons
WHERE Company LIKE '".$ID."'");


-Butcher-

[This message has been edited by butcher (edited 03-08-2004).]

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-08-2004 02:47

thanks butcher. I changed the hyperlink and still not working. I made sure I was consistant with using $Company and not $ID . . . I'll keep plugging away.

my page

[This message has been edited by CRO8 (edited 03-08-2004).]

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-08-2004 02:59

Have you tried echoing $Company in your script to make sure your receiving what you think you are after the link is clicked?

-Butcher-

[This message has been edited by butcher (edited 03-08-2004).]

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-08-2004 03:44

you mean a similar echo as in skarjj's code?

echo '<a href="Greg_Apple_2.php?ID='.$coupon_obj->Company.'">'.$coupon_obj->Coupon.'</a><BR />";}

[This message has been edited by CRO8 (edited 03-08-2004).]

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 03-08-2004 07:34

I think he just means:

echo $_GET["Company"];

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-08-2004 13:24

thanks . . . tried it but to no avail.

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-08-2004 21:38

CRO8

I meant to put something like

echo 'Company = '.$_GET["Company"];

in your Greg_Apple_2.php code somewhere to see if the variable is actually being passed as you think it is.

-Butcher-

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-09-2004 01:22

hey butcher thanks. yeah I put your code in my Greg_Apple_2.php file and I still get a blank page. I'll re look at my code and see what I am missing.

I guess to sum up, this is the code associated with the "Dell" hyperlink.

<a href="Greg_Apple_2.php?Company=Dell">Dell</a>

//from skarjj ozoneasylum
$query = "SELECT Company FROM coupons ORDER BY ID ASC";
$result = mysql_query($query);
$coupon_obj = $mysql_fetch_object($result);
while ($coupon_obj){echo '<a href="Greg_Apple_2.php?Company='.$coupon_obj->Company.'">'.$coupon_obj->Coupon.'</a><BR />";}
echo 'Company = '.$_GET["Company"];


[This message has been edited by CRO8 (edited 03-09-2004).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-09-2004 09:14

well, $_GET['company'] would only be set in Greg_Apple_2.php, after you clicked a link.
It wouldn't be set when you are first printing the hyperlinks.

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-09-2004 13:27

ok bare with me, I'm learning php. Is this what you had in mind? I took it out underneath printing, and placed it first in Greg_Apple_2.php file. Still I get a blank page when I click on the "Dell" hyperlink. So my files are:


Greg.html:
<a href="Greg_Apple_2.php?Company=Dell">Dell</a>


Greg_Apple_2.php
echo 'Company = '.$_GET["Company"];

//from skarjj ozoneasylum
$query = "SELECT Company FROM coupons ORDER BY ID ASC";
$result = mysql_query($query);
$coupon_obj = $mysql_fetch_object($result);
while ($coupon_obj){echo '<a href="Greg_Apple_2.php?Company='.$coupon_obj->Company.'">'.$coupon_obj->Coupon.'</a><BR />";}

Am I getting closer?

Thanks.

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 03-10-2004 02:42

CRO8, what you have there should at least show you "Company = Dell" in your browser.

I just copied your link: <a href="Greg_Apple_2.php?Company=Dell">Dell</a> into an html file by itself.

Then I created a Greg_apple_2.php file with this code in it:

echo 'Company = '.$_GET["Company"];

When I click on the link I see: Company = Dell in my browser. As I said you should at least be seeing that. When you do your db query will work.

-Butcher-

[This message has been edited by butcher (edited 03-10-2004).]

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-10-2004 04:01

hey butcher- yup sure, I replicated your example and after clicking on the Dell link, I see:

Company = Dell

ok, let me add the code piece by piece . . . and try to get this thing to work.

thanks.

10 minutes later . . . .

it works- check it out and click Dell link

THANKS EVERYONE

[This message has been edited by CRO8 (edited 03-11-2004).]

« BackwardsOnwards »

Show Forum Drop Down Menu