Jump to content

Veteah

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

About Veteah

  • Birthday 01/08/1986

Profile Information

  • Gender
    Male
  • Location
    England

Veteah's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. In that case, all you have to do is add include('file_path'); ... where the echo is.
  2. There's not really a standard, but it would be worth your time reading up on sql injection attacks, as well as things like mysql_real_escape_string, magic_quotes, add_slashes and regex used in preg_*.
  3. I think see what you're trying to do. Say you had an item's id passed through $_POST $colours = array(1 => 'EE0000', 2 => 'E3CF57', 3 => '6E8B3D', 4 => '00688B', 5 => '8968CD'); $item_id = preg_replace("/[^\d\]/", "", $_POST['id']); // remove everything that's not a number $sql = "SELECT `item_name`, `item_colour` FROM item_table WHERE item_id = '". $item_id ."'"; $run = mysql_query($sql); $row = mysql_fetch_assoc($run); $selected_colour = $row['item_colour']; $selected_name = $row['item_name']; /* Say the field item_colour is a number from 1 to 5 depending on what colour you want it to be. You would then use the field to act as the means of selecting the array key from $colours */ echo '<p style="color: #'. $colours[$selected_colour] .';">'. $selected_name .'</p>'; So if the query came back as 3 for item_colour the above would be the same as saying: <p style="color: #'. $colours[3] .';">'. $selected_name .'</p> Which would make the page's html be: <p style="color: #6E8B3D;">ITEM NAME</p> Hope that helps.
  4. Also, just to point out, you're using $result incorrectly. All it does is tell you whether the query failed or not, not if it returned any rows like it looks like you're trying to see. For that you should use mysql_num_rows(), but yeah, you should do password verification before you start making queries.
  5. It's sort of an awkward way of doing things. Try something like: $table_array = array('table_one', 'table_two', 'table_three'); foreach($table_array as $key => $value) { $sql = "SELECT * FROM ". $value ." WHERE id = '". $id ."'"; $run = mysql_query($sql); while($row = mysql_fetch_assoc($run) { $everything_ever[] = $row; } } That will give you a multidimensional array with all the results from all the tables you specify. From there you can get to them by going: foreach($everything_ever as $key => $value) { echo $everything_ever[$key]['field_one']; echo $everything_ever[$key]['field_two']; echo $everything_ever[$key]['field_three']; }
  6. Yep, if you had say: <form action="somepage.php" method="post"> <input type="text" name="english_somthing" /> <input type="submit" name="submit_english" /> </form> <form action="somepage.php" method="post"> <input type="text" name="spanish_somthing" /> <input type="submit" name="submit_spanish" /> </form> If you were to press submit one the English form, only the input from that form, not the Spanish, would be passed.
  7. Yep, although to be honest it's simpler (at least I think so) to change the timestamp to a simple int field. From there, everytime you make an update query or insert a new value add put in something like: $sql = "UPDATE table_name SET *your_fields_here*, date = ". strtotime('now'); $run = mysqli_query($sql);
  8. Do you mean something like: $assignedtree = $_SESSION['assignedtree']; $currentuser = $_SESSION['currentuser']; if($assignedtree == 'tree1') { echo $currentuser . ' is looking at tree 1'; } elseif($assignedtree == 'tree2') { echo $currentuser . ' is looking at tree 2'; } else { echo $currentuser . ' did not match either tree'; } Replacing the tree1 and tree2 with whatever you're storing in the session.
  9. You'd want to put mysql_fetch_array($sql, MYSQL_NUM) or mysql_fetch_array($sql, MYSQL_ASSOC) Yeah, and loop it. Obviously
  10. This is untested so you'll probably have to fiddle with it, but try <?php $var = (isset($_GET['search'])) ? $_GET['search'] : ''; $searchtype = (isset($_GET['searchtype'])) ? $_GET['searchtype'] : ''; $post_limit = (isset($_GET['l'])) ? $_GET['l'] : 0; $isbn = "ISBN"; $school = "School"; $title = "Title"; $subject = "Subject"; $post_limit = (int) preg_replace("/[^\d\]/", "", $post_limit); $post_limit = (empty($post_limit)) ? 0 : $post_limit; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit = 10; if(empty($trimmed)) { echo "<p>Please enter a search...</p>"; exit; } //connect to your database $connect = mysql_connect() or die("Not connected"); //specify database mysql_select_db("collegebooxboox") or die("could not log in"); switch($searchtype) { case $title: default: $sql_field = 'name'; break; case $school: $sql_field = 'school'; break; case $isbn: $sql_field = 'isbn'; break; case $subject: $sql_field = 'subject'; break; } $sql = "SELECT * FROM `boox` WHERE ". $sql_field ." LIKE ". $trimmed; $run = mysql_query($sql) or die('error:<br/>' . mysql_error()); $num = mysql_num_rows($run); $p_total_rows = 'There are ' . $num . ' results'; if($num > $limit) { $sql = $sql . 'ORDER BY ' . $sql_field . ' ASC LIMIT '. $post_limit .', '. $limit; $run = mysql_query($sql) or die('error:<br/>' . mysql_error()); } while($row = mysql_fetch_array($run, MYSQL_ASSOC)) { // echo your results here } $link_prev = $post_limit - 10; $link_prev = (0 > $post_limit) ? 0 : $link_prev; $link_next = $post_limit + 10; ?> In which case your next and previous links would look like this <?php $url = $_SERVER['script_name']; echo '<a href="'.$url.'?l='.$link_prev.'">Previous</a>'; echo '<a href="'.$url.'?l='.$link_next.'">Next</a>'; ?> Also, you really, really really need to put some sort of checking on those $_GETs
  11. There's a few things, for one mysql_fetch_assoc will return a numeric array unless you tell it not to be doing mysql_fetch_array($result, MYSQL_ASSOC) Other than that, your first sql query is selecting multiple rows but you're not looping the results.
×
×
  • 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.