Jump to content

champbronc2

Members
  • Posts

    45
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

champbronc2's Achievements

Member

Member (2/5)

0

Reputation

  1. So I have a MySQL database table that stores order ID and prices. The price can either be dynamic or static. So for example: Order ID | Price 1|205.99 2|215.95 3|217.88 4|$marketrate 5|$marketrate*1.02 6|212.99 On my php page I have include "prices.php"; $sql="Select `Order ID`, `Price` from `table` ORDERBY `price`"; $result=mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo "<tr ".$tr_class.">\n"; foreach ($row as $field=>$value) { eval('$value = ' . $value . ';'); echo "<td>" . $value . "</td>\n"; } echo "</tr>\n"; } So you see I use eval() to evaluate the price variable and display it and prices.php defines all the prices like $marketrate and whatnot. My question is, how can I orderby the evaluated prices? When I use orderby in my mysql statement, it sorts the array based on static numbers and then the variable names $marketrate, which obviously is wrong because $marketrate is not a number. I need it to sort the array according to what the evaluated value of $marketrate is. **Is it possible to somehow evaluate all the variables in the $result array, and then re-sort the array using a PHP sorting function?** edit: tried to put eval('$result['Price'] = ' . $result['Price'] . ';'); in there but it did not work.
  2. Ohh, got it. Sorry, I am still learning but thanks for the help!! Works now.
  3. <?php $id = $_GET['d']; $servername="localhost"; $username="c_links"; $password="pass"; $conn= mysql_connect($servername,$username,$password)or die(mysql_error()); mysql_select_db("c_links",$conn); $query1 = mysql_query("SELECT url FROM links WHERE id='$id'"); $url = mysql_fetch_array($query1) or die(mysql_error()); $query2 = mysql_query("SELECT name FROM links WHERE id='$id'"); $name = mysql_fetch_array($query2) or die(mysql_error()); $query3 = mysql_query("SELECT size FROM links WHERE id='$id'"); $size = mysql_fetch_array($query3) or die(mysql_error()); ?> <html> blah blah blah <?php eco $id; ?> //THIS ONE ACTUALLY WORKS <?php echo $url; ?> <?php echo $name; ?> <?php echo $size; ?> </html> When I do this and I go to http://example.com/?d=xxxx, where ever I have $url $name and $size in my html, the output is "Array" when it should be actually outputting a URL or a name or size. The $id one is the only one that works in the HTML body. The page completely loads and there are no error messages displayed. What is wrong with the code? Shouldn't it query my database, then when I run fetch_array store whatever the result is into the variable??? Thanks for any help!
  4. It works perfect now. Thank you very much.
  5. Ohhh. Well thanks it works now!!! Only problem is the IP address isn't showing up now...?
  6. Ok nevermind I can't edit. New code is here <? if (isset($_POST["email"])) { mysql_connect('localhost', 'champbux_raffle', 'raffle'); $con=mysql_connect('localhost', 'champbux_raffle', 'raffle'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("champbux_raffle", $con); $email = $_POST['email']; $Country = $_POST['Country']; $ip=@$REMOTE_ADDR; $sql = "INSERT INTO Users (Email, Country, IP) VALUES ($email, $Country, $ip)"; mysql_query($sql) or die(mysql_error()); echo "You have been registered correctly"; } ?> <form action="raffle.php" method="post"><strong>YOUR IP ADDRESS IS BEING RECORDED</strong> By registering you agree to the terms that we are not held liable for anything wrong with the jersey and that you may only enter ONCE. After 200 participants have registered, one winner will be randomly chosen. An email will be dispatched to the winner. Please add raffle@champbux.com to your white list. Prizes not claimed within 72 hours will be forfeited and another winner will be chosen. All entrants will be screened for cheating. Shipping will be free to the United States. You will only have access to this page for 24 hours after the survey is completed. This is to prevent cheating. Your information will NEVER be disclosed to anyone or used for malicious purposes. <table border="0" width="400" align="center"> <tbody> <tr> <td width="150" align="left"><label>Email address</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="email" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"><label>Country (Shipping will NOT be free if outside of US)</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="Country" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"></td> <td width="250" align="right"><input class="submit" type="submit" value="Submit" tabindex="6" /></td> </tr> </tbody> </table> </form>
  7. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com, US, )' at line 1 I get that message after hitting submit now while testing it. I changed the code. The new code is in the original post.
  8. That is all my code. I am really new and pretty much suck. And the thing is, I am using wordpress so my page is http://website.com/page/ so I don't know what to put instead of <?php echo $_SERVER['PHP_SELF']."?register=true" ?>
  9. $sql = "INSERT INTO tb_Users (Email, Country, IP) VALUES ($email, $Country, $ip)"; mysql_query($sql) or die(mysql_error()); echo "You have been registered correctly"; Tried changing it to that. It still won't work. I tried to submit it, and no errors seem to occur but the database is empty. And it does not echo You have been registered correctly.
  10. <?php function registerUser() { mysql_connect('localhost', 'site_raffle', 'raffle', 'site_raffle'); $email = $_POST['email']; $Country = $_POST['Country']; $ip=@$REMOTE_ADDR; $sql = "INSERT INTO tblUsers (fldEmail, fldCountry, fldIP) VALUES ($email, $Country, $ip);"; mysql_query($sql); } ?> <form action="<?php $_SERVER['PHP_SELF']."?register=true" ?>" method="post"> <table border="0" width="400" align="center"> <tbody> <tr> <td width="150" align="left"><label>Email address</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="email" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"><label>Country (Shipping will NOT be free if outside of US)</label></td> <td width="250" align="left"><input class="field" maxlength="100" name="Country" size="25" type="text" tabindex="1" /></td> </tr> <tr> <td width="150" align="left"></td> <td width="250" align="right"><input class="submit" type="submit" value="Submit" tabindex="6" /></td> </tr> </tbody> </table> </form> What is wrong with the code?? I will go to my webpage, fill out the fields, and hit submit. I check the database, and no new information has been entered...
  11. OK, I have a column in my database labeled expiredate and it is a date column. How can I have a query that will do this: $query = mysql_query("UPDATE users SET expiredate='CURDATE()+30days', referer='$username' WHERE referer='available' SORT BY visits DESC"); Then I also need something that will do this: $query = mysql_query("UPDATE users SET referer='' WHERE expiredate is before the current date") I will pay $5 PayPal if someone can help, and give an explanation.
×
×
  • 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.