Jump to content

matthewst

Members
  • Posts

    215
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

matthewst's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks for having a look. Lets use Tulsa OK for our first query: SELECT all rest_id's FROM the restaurant_info table WHERE state OK and city = Tulsa and put the results in an array called rest_ids Then I use foreach for table cell 1: for array variable 0 select the related info from the database and echo it - if ad1 = '' then echo "make a check box" then for array variable 1 select the related info from the database and echo it - if ad1 = '' then echo "make a check box" Foreach for table cell 2: for array variable 0 select the related info from the database and echo it - if ad2 = '' then echo "make a check box" then for array variable 1 select the related info from the database and echo it - if ad2 = '' then echo "make a check box" The problem is the name of the variable $id is the same each time the query executes. Each cell my contain 30 entries and the table may have 50 cells. How do I tell my processing page I want to tick the box for entry 1 in cell 2? $Get_City = mysql_query("SELECT rest_id FROM restaurant_info WHERE state = '$state' AND city = ('$selected_cities') ORDER BY rest_id"); $rest_ids = array(); while ($got_city = mysql_fetch_array($Get_City)) { $rest_ids[] = $got_city[0]; } //print_r(array_values($rest_ids)); echo "<form name='mark_sold' action='mark_sold.php' enctype='multipart/form-data' method='post'><table width='1100' border='1'><tr><td><h2>Spot 1</h2>"; foreach ($rest_ids as $id){ //$rest_ids = implode("' or '", $rest_ids); //$rest_ids = "'" . $rest_ids . "'"; $Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space1 FROM restaurant_info WHERE rest_id = $id"); ///////////right here $id = 1, but the next time it will be 2 and so on --- when i process my form $id is always the last rest_id processed $got_ad = mysql_fetch_assoc($Get_Ad); $is_sold = $got_ad['ad_space1']; $rest_id = $got_ad['rest_id']; $rest_name = $got_ad['rest_name']; $city = $got_ad['city']; if($is_sold){ $is_sold = "<font color='red'>sold</font>"; }else{ $is_sold = "<font color='green'>available</font><input name='ad1' id='ad1' type='checkbox' value='1'/><input name='rest_id' type='hidden' value='" .$rest_id."' />"; } echo $rest_name." in ". $city." is ".$is_sold."<br />"; } echo "</td><td><h2>Spot2</h2>";
  2. That's half my problem, I don't understand most of what I'm coding. Here's what's going on: query database and display results in a table like so rest name 1 spot 1_sold___rest name 1 spot 2_avail__rest name 1 spot 3_avail rest name 2 spot 1_sold___rest name 2 spot 2_avail__rest name 2 spot 3_sold rest name 3 spot 1_avail__rest name 3 spot 2_avail___rest name 3 spot 3_sold I've got that done. The problem is my $id variable is different with each loop. So when I use the (avail)check box on "rest name 1 spot 3" my form process page gets the $id of rest name 3 because that was what the last loop assigned. I'm sure there is a better way to do this but I don't know it. Thank you for any help you can offer. I think maybe I'm misunderstanding how to use foreach.
  3. Yeah, I'm an idiot but my question is still the same. How do I get the array values or variables into my looped update query? Right now I'm using foreach to echo the results but then my $id = whatever the last result is. I need $id from loop 1 then $id from loop 2 and so on. <?php include('include/db_con.php'); if (!$radius){ $radius = '1'; } $get_lat = "SELECT AVG(latitude) FROM zipcodes WHERE city = '$city' AND state = '$state'"; $got_lat = mysql_query($get_lat); $rowlat = mysql_fetch_array($got_lat); $lat = $rowlat[0]; $get_lon = "SELECT AVG(longitude) FROM zipcodes WHERE city = '$city' AND state = '$state'"; $got_lon = mysql_query($get_lon); $rowlon = mysql_fetch_array($got_lon); $lon = $rowlon[0]; $coords = array('latitude' => $lat, 'longitude' => $lon); $sql = "SELECT DISTINCT city, ( 3959 * acos( cos( radians( {$coords['latitude']} ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( {$coords['longitude']} ) ) + sin( radians( {$coords['latitude']} ) ) * sin( radians( latitude ) ) ) ) AS distance FROM zipcodes HAVING distance <= {$radius} ORDER BY distance"; $query = mysql_query($sql); //while($row = mysql_fetch_assoc($query)){ //$selected_cities = $row['city']; //echo "$$" . $selected_cities . "$$<br />"; $names = array(); while ($row = mysql_fetch_array($query)) { $names[] = $row[0]; } $selected_cities = implode("' or '", array_unique($names)); //echo "{$row['city']} {$row['zipcode']} ({$row['distance']})<br>\n"; //echo $selected_cities; $Get_City = mysql_query("SELECT rest_id FROM restaurant_info WHERE state = '$state' AND city = ('$selected_cities') ORDER BY rest_id"); $rest_ids = array(); while ($got_city = mysql_fetch_array($Get_City)) { $rest_ids[] = $got_city[0]; } print_r(array_values($rest_ids)); echo "<form name='mark_sold' action='mark_sold.php' enctype='multipart/form-data' method='post'><table width='1100' border='1'><tr><td><h2>Spot 1</h2>"; foreach ($rest_ids as $id){ //$rest_ids = implode("' or '", $rest_ids); //$rest_ids = "'" . $rest_ids . "'"; $Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space1 FROM restaurant_info WHERE rest_id = $id"); $got_ad = mysql_fetch_assoc($Get_Ad); $is_sold = $got_ad['ad_space1']; $rest_id = $got_ad['rest_id']; $rest_name = $got_ad['rest_name']; $city = $got_ad['city']; if($is_sold){ $is_sold = "<font color='red'>sold</font>"; }else{ $is_sold = "<font color='green'>available</font><input name='ad1' id='ad1' type='checkbox' value='1'/><input name='rest_id' type='hidden' value='" .$rest_id."' />"; } echo $rest_name." in ". $city." is ".$is_sold."<br />"; } echo "</td><td><h2>Spot2</h2>"; foreach ($rest_ids as $id){ //$rest_ids = implode("' or '", $rest_ids); //$rest_ids = "'" . $rest_ids . "'"; echo $id; $Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space2 FROM restaurant_info WHERE rest_id = $id"); $got_ad = mysql_fetch_assoc($Get_Ad); $is_sold = $got_ad['ad_space2']; $rest_id = $got_ad['rest_id']; $rest_name = $got_ad['rest_name']; $city = $got_ad['city']; if($is_sold){ $is_sold = "<font color='red'>sold</font>"; }else{ $is_sold = "<font color='green'>available</font><input name='ad2' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />"; } echo $rest_name." in ". $city." is ".$is_sold."<br />"; } echo "</td><td><h2>Spot 3</h2>"; foreach ($rest_ids as $id){ //$rest_ids = implode("' or '", $rest_ids); //$rest_ids = "'" . $rest_ids . "'"; $Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space3 FROM restaurant_info WHERE rest_id = $id"); $got_ad = mysql_fetch_assoc($Get_Ad); $is_sold = $got_ad['ad_space3']; $rest_id = $got_ad['rest_id']; $rest_name = $got_ad['rest_name']; $city = $got_ad['city']; if($is_sold){ $is_sold = "<font color='red'>sold</font>"; }else{ $is_sold = "<font color='green'>available</font><input name='ad3' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />"; } echo $rest_name." in ". $city." is ".$is_sold."<br />"; } echo "</td><td><h2>Spot 4</h2>"; foreach ($rest_ids as $id){ //$rest_ids = implode("' or '", $rest_ids); //$rest_ids = "'" . $rest_ids . "'"; $Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space4 FROM restaurant_info WHERE rest_id = $id"); $got_ad = mysql_fetch_assoc($Get_Ad); $is_sold = $got_ad['ad_space4']; $rest_id = $got_ad['rest_id']; $rest_name = $got_ad['rest_name']; $city = $got_ad['city']; if($is_sold){ $is_sold = "<font color='red'>sold</font>"; }else{ $is_sold = "<font color='green'>available</font><input name='ad4' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />"; } echo $rest_name." in ". $city." is ".$is_sold."<br />"; } echo "</td><td><h2>Spot 5</h2>"; foreach ($rest_ids as $id){ //$rest_ids = implode("' or '", $rest_ids); //$rest_ids = "'" . $rest_ids . "'"; $Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space5 FROM restaurant_info WHERE rest_id = $id"); $got_ad = mysql_fetch_assoc($Get_Ad); $is_sold = $got_ad['ad_space5']; $rest_id = $got_ad['rest_id']; $rest_name = $got_ad['rest_name']; $city = $got_ad['city']; if($is_sold){ $is_sold = "<font color='red'>sold</font>"; }else{ $is_sold = "<font color='green'>available</font><input name='ad5' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />"; } echo $rest_name." in ". $city." is ".$is_sold."<br />"; } echo "</td></tr><tr><td><h2>Spot 6</h2>"; foreach ($rest_ids as $id){ //$rest_ids = implode("' or '", $rest_ids); //$rest_ids = "'" . $rest_ids . "'"; $Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space6 FROM restaurant_info WHERE rest_id = $id"); $got_ad = mysql_fetch_assoc($Get_Ad); $is_sold = $got_ad['ad_space6']; $rest_id = $got_ad['rest_id']; $rest_name = $got_ad['rest_name']; $city = $got_ad['city']; if($is_sold){ $is_sold = "<font color='red'>sold</font>"; }else{ $is_sold = "<font color='green'>available</font><input name='ad6' type='checkbox' value='1' />"; } echo $rest_name." in ". $city." is ".$is_sold."<br />"; } //blah blah blah echo "</td></tr><tr><td colspan='5'><center><input type='submit' name='submit' value='Submit'></center></td></tr></table></form>"; mysql_close(); ?> And here is my update query mysql_query("UPDATE restaurant_info SET ad_space1='$ad1', ad_space2='$ad2' WHERE rest_id='$rest_id'") or die(mysql_error());
  4. How do I do this? loop a query for id numbers and related info and assign the results to variables named from the array example loop 1:$0id = id, $0related_info = related_info example loop 2:$1id = id, $1related_info = related_info then, on my processing page take those variables and loop 1: UPDATE table SET info = $0stuff_from_form WHERE id = $0id then loop 2: UPDATE table SET info = $1stuff_from_form WHERE id = $1id and so on
  5. Got it!! I just have to use the following code for each <option>. <?php if(mysql_num_rows(mysql_query("SELECT whatev FROM some_table WHERE number = 1 AND person_id = '".$q."'"))){ echo "<option value='1' disabled>1</option>"; }else{ echo "<option value='1'>1</option>"; } ?> BTW Andrew, have you seen Bubba Ho-Tep?
  6. Now that I think about it, that is a little convoluted. To make things a little clearer. How do I write a query and php to display in a drop down data that is NOT in a database?
  7. Fair enough. I have multiple tables in a database, one table holds the max number of widgets, somewhere between 20 and 30. For this I'll say max is 20. The first drop down on the form (the one NOT shown) gives me my $q variable that get_quote_num.php uses to dynamically display the second drop down (the one I displayed in post one). In another table I have listed users and the widgets that are already taken. example: user 1 widget 1 user 1 widget 3 My question is how do I write a query or some php to only show select options 2, 4-20? $sql="SELECT oak_spaces FROM data_table WHERE id = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { //I assume the new query will need to go here //something like //$sql = "select widgets from table where user = user" //which will give me 1 and 3 //now echo "<select>" //!!!!!!right here, how do I NOT display<option value'1'> but skip to 2 like below ?> <select name="quote_num" class="formTextbox" size="1"> <option value="2">2</option> <option value="4">4</option> <option value="5">5</option>
  8. Example table 1: person: 1 oak_spaces: 5 person: 2 oak_spaces: 8 My first drop down will select the correct work number. The second drop down(the one listed below) will then display the appropriate number of options. Example table 2: person: 1 space: 2 person: 1 space: 3 person: 1 space: 5 How would I make my drop down only show options 1 and 4? $sql="SELECT oak_spaces FROM data_table WHERE id = '".$q."'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { //the above query will get me the maximum number of options to display //how do I set up my query (for table 2) and php to only echo 1 and 4? (in this example 5 is the max) ?> <select name="quote_num" class="formTextbox" size="1"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <?php if ($row['oak_spaces'] > '20'){ ?> <option value="21">21</option> <option value="22">22</option> <?php } if ($row['oak_spaces'] > '22'){ ?> <option value="23">23</option> <option value="24">24</option> <?php } if ($row['oak_spaces'] > '24'){ ?> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <?php } if ($row['oak_spaces'] > '28'){ ?> <option value="29">29</option> <option value="30">30</option> <?php } } ?> </select> Maybe a preg_match? Or a preg_not_match?
  9. As it turns out I'm an idiot. After checking the database and NOT seeing a billion new records I realized it was just sending me the notification email. So, I moved mail() to the inside of my if($_POST brackets. All is now right with the world.
  10. I have a form that submits to itself (I know it should submit to a handler but that's the way it was when I took over.). I've had to add a dynamic dropdown menu to the page. The dropdown works like it should except now the page submits every time it loads. <? include('include/user_check.php'); include('include/db_con.php'); $id = $_SESSION['track_id']; $dest_email='email@server.com'; set_time_limit ( 0 ); //error_reporting(E_ALL); if($_POST['submit']) { blah blah php stuff javascript var xmlhttp; function showUser(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="get_quote_num.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } start of form <form action="<?=$PHP_SELF;?>" method="post" enctype="multipart/form-data" name="FormName" onSubmit="MM_validateForm('company','','R','address','','R','city','','R','RisNum','phone','','R','size','','R','ad_num','','R','quote_num','','R');return document.MM_returnValue;return Form1_Validator(this)"> new dropdown (the disabled dropdown is replaced by the working one once a selection is made in another menu [/code]<td> <div id="txtHint"> <select name='quote_num' class='formTextbox' size='1' disabled='disabled'> <option value=''>Select from other dropdown first</option> </select> </div> </td>[/code] get_quote_num.php page <?php $q=$_GET["q"]; include('include/db_con.php'); <select> blah blah this works fine </select> back to the form <input type="submit" class="formTextbox" name="submit" value="Submit"> It doesn't submit when I use the dropdowns. Only when it loads. When I actually click the submit button it submits twice!
  11. My mistake. Select Missouri, Osage Beach for an example
  12. Here's what I have so far: First drop down = select a state (works) This populates the second drop down (works) Second drop down = select a city (works) This populates the third drop down with local restaurant names (not quite) When I select a restaurant from the drop down the form is submitted but the $rest_name variable isn't carried over Site: www.abcgreatdeals.com Select:California, La Quinta for an example I'm sure it's something simple that I'm just over looking. Thanks for any input. <form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> <?php if (isset ($_POST['state'])) { if ($state == '99') { ?> <script type="text/javascript"> <!-- window.location = "http://www.abcgreatdeals.com" //--> </script> <?php } ?> <select name="state" CLASS="formTextbox" onchange="form1.submit();"> <option value="<?=$state;?>"><?=$state;?></option> <option value="99">Start Over</option> <?php } else{ $Get_State = mysql_query("SELECT DISTINCT state FROM coupons ORDER BY state",$db_link); ?> <select name="state" CLASS="formTextbox" onchange="this.form.submit();"> <OPTION SELECTED VALUE="">Select A State</OPTION> <? while($get_it = mysql_fetch_array($Get_State)) { ?> <option value="<?=$get_it['state'];?>"><?=$get_it['state'];?></option> <? }} if (isset ($_POST['state'])) {?> </select> </form> <form id="form2" name="form2" method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> <?php if (isset ($_POST['city']) != '') { if ($city == '99') { ?> <script type="text/javascript"> <!-- window.location = "http://www.abcgreatdeals.com" //--> </script> <?php } ?> <input type="hidden" name="state" value="<?="$state"; ?>"> <select name="city" CLASS="formTextbox" onchange="form2.submit();"> <option value="<?=$city;?>"><?=$city;?></option> <option value="99">Start Over</option> <?php } else{ $Got_City = mysql_query("SELECT DISTINCT city FROM coupons WHERE state='$state' ORDER BY city",$db_link); ?> <input type="hidden" name="state" value="<?="$state"; ?>"> <select name="city" CLASS="formTextbox" onchange="form2.submit();"> <OPTION SELECTED VALUE="">Select A City</OPTION> <? while($got_it = mysql_fetch_array($Got_City)) { ?> <? if ($got_it['city'] != ''){ ?> <option value="<?=$got_it['city'];?>"><?=$got_it['city'];?></option> <? } else { ?> <option value="99">Start Over</option> <? } ?> <? }} if (isset ($_POST['city'])) {?> </select> </form> <form id="form3" name="form3" method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> <?php if (isset ($_POST['rest']) != '') { if ($rest == '99') { ?> <script type="text/javascript"> <!-- window.location = "http://www.abcgreatdeals.com" //--> </script> <?php } ?> <input type="hidden" name="city" value="<?="$city"; ?>"> <input type="hidden" name="state" value="<?="$state"; ?>"> <select name="rest" CLASS="formTextbox" onchange="form3.submit();"> <option value="<?=$rest_name;?>"><?=$rest_name?></option> <option value="99">Start Over</option> <?php } else{ $Get_Rest = mysql_query("SELECT DISTINCT rest_name FROM coupons WHERE state='$state' AND city='$city'",$db_link); ?> <input type="hidden" name="state" value="<?=$state?>"> <input type="hidden" name="city" value="<?=$city?>"> <select name="rest" CLASS="formTextbox" onchange="form3.submit();"> <OPTION SELECTED VALUE="">Select A Restaurant</OPTION> <? while($got_rest = mysql_fetch_array($Get_Rest)){ $rest_name = stripslashes($got_rest['rest_name']); ?> <option value="<?=$rest_name;?>"><?=$rest_name?></option> <? }}}} if (isset ($_POST['rest'])) {?> </select> </form> <?php if ($rest_name){ echo "<strong>Click on coupons to print individually</strong><br><br>"; } if ($rest_name) { $Get_Coupons = mysql_query("SELECT * FROM coupons WHERE rest_name='$rest_name' ORDER BY coupon_rank DESC",$db_link);
  13. GOT IT!! $insert = imagecreatefromjpeg('image.jpg'); $im = imagecreatetruecolor(1800, 600); $white = imagecolorallocate($im, 255, 255, 255); imagefill ( $im, 0, 0, $white ); Thanks!
  14. When I change: $im = imagecreate(1800, 600); to $im = imagecreatetruecolor(1800, 600); The original image is flawless but the canvas or "background" turns black. If someone can tell me how to change that to white or transparent then I'll be all set.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.