Closed Thread Icon

Topic awaiting preservation: pull downs with ONE submit button (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13105" title="Pages that link to Topic awaiting preservation: pull downs with ONE submit button (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: pull downs with ONE submit button <span class="small">(Page 1 of 1)</span>\

 
CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-24-2004 04:51

Basically I am trying to compare two items and query info from mysql dbase. (2 pull down menus with one submit button). Geez, is this even possible?

This is what I came up with. When I test it on my mysql dbase- it only returns results from second pull down menu. I have a feeling I need to have <select name="Company_1"> and <select name="Company_2"> and point them to separate columns in dbase. Am I on correct track?

<form method=post action="Greg_Apple_3.php">
<select name="Company">
<option selected value="Apple">Apple</option>
<option value="Penthouse">Penthouse</option>
</select>

<select name="Company">
<option selected value="Dell">Dell</option>
<option value="Penthouse">Penthouse</option>
</select>
<center><input type="submit" value="Compare Coupons"></center>
</form>

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 03-24-2004 05:54

Well you definately can't have two with the same name. They need different names but after that you can still compare them to the same column.


select * from whatever
where company like '$Company1'
OR comany like '$Company2'

or something like that.




.:[ Never resist a perfect moment ]:.

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-24-2004 06:35

hey thanks BD- yeah I have my pull downs pointing towards Company and Company_b columns in the dbase. As of now its only retrieving Company_b results. I need to do some more digging, its 12:30am Tuesday night. Bedtime

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-24-2004 09:18

and we need to see all of the code - this is pretty basic stuff, so if you want help, you'll only get it by making it as easy as possible on us to answer.

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-24-2004 13:27

ok Tiberius- here is the code in receiving php file. I think I have the correct code to interpret Company but maybe its the print portion- its not specific to Company or Company_b, just "coupon" which could be either . . .

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


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


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

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


// 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-24-2004).]

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 03-24-2004 15:38

You're not getting the answer to the first question
SELECT Company,Coupon
FROM coupons
WHERE Company LIKE '".$Company."'");
'cuz you're not asking for it.

Look, you've set this to the variable $result
Then, in the very next line, you set $result to your second question.
So later when you wish to loop through all the results, you're using
$row = mysql_fetch_array($result)
and $result has already been changed.

I think you want to set $result one time w/ SQL like this:

SELECT company, company_b, coupon
FROM coupons
WHERE company LIKE '$company'
OR company LIKE '$company_b'

I don't have a good handle on your data structure, so I'm not exactly sure...but I'm making a guess and I think this is what you want to do.

Also, use mysql_num_rows($result) to do your counting.
It's faster and a lot more efficient than actually doing a select statement.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-24-2004 20:38

^^ - what he said.

And you also shouldn't be using 'like' like this. If you're looking for an exact name, use '='. Otherwise, use the placeholders for like.

And you could probably be using mysql_num_rows instead of your additional query for the amount ('count') of coupons.

so long,

Tyberius Prime

CRO8
Bipolar (III) Inmate

From: New York City
Insane since: Jul 2000

posted posted 03-25-2004 04:00

Thanks guys- I'll play around and re-post with progress.

Thanks!

« BackwardsOnwards »

Show Forum Drop Down Menu