Jump to content

tchick

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by tchick

  1. Thanks Muddy_Funster, that sorted it.
  2. Hi All, I am trying to pull a record from my table using the date of birth column (which is a date column) like so.. $birthday = ('1936-08-21'); $query = "Select * from my_table where dob = $birthday"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ echo "Name is - " .$row['name']; } I know there is a record in the table with a date of birth(dob) value of 1936-08-21 but it does not return any records ? thanks for looking, Tony
  3. That got the page links sorted, thanks nethnet. I made both these the same for($i = 1; $i <= $rows; $i++) { if($page < $rows){ this gives me [Prev] 1 2 3 4 [Next] which works fine. The problems i have left now are lets say i select 'B' and male it works correct and shows me the 3 male records i have, but the page numbers are still [Prev] 1 2 3 4 [Next] when i only want to show page links if there are more than one page?. The other problem i have still is if i select the link 'show all' i get the Notice: Undefined index: letter in C:\wamp\www\public_html\alpha3.php on line 11 error? Thanks for your help so far with this one. Regards Tony
  4. Hi nethnet, Thanks for the alterations to the code your changes certainly made the difference, almost got it working as i want with a few more changes. I can now select letter and gender and works fine, just a small problem with the pagination now. Seems if no more than one page worth of results it still shows forward and backward pages so i need to try to eliminate that bit. Here is the code to date. Regards Tony <?php session_start(); include("common.php"); for ($i = ord("A"); $i < ord("Z"); $i++) echo "<a href=\"alpha3.php?letter=" . chr($i) . "\">" . chr($i) . "</a> ¦ "; echo "<br>"; if (!isset($_POST['submit'])) { echo "<a href=\"?\">Show All</a></p><br /> <form method=\"post\" action=\"?\"> Select Gender :<br> Male:<input type=\"radio\" value=\"male\" name=\"gender\"><br> Female:<input type=\"radio\" value=\"female\" name=\"gender\"><br> <input type=\"hidden\" name=\"letter\" value=\"{$_GET['letter']}\" /> <input type=\"submit\" name=\"submit\" value=\"Search\" class=\"submit\" /> </form>"; } else { Echo "form has been submited"."<br>"; } mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); $page = (empty($_GET['page'])) ? 1 : $_GET['page']; $letter = (empty($_GET['letter'])) ? "%" : $_GET['letter']; $gender = (empty($_GET['gender'])) ? "%male" : $_GET['gender']; $max_results = 4; $from = (($page * $max_results) - $max_results); if(empty($_POST)) { $query = "SELECT * FROM `contacts` WHERE `fname` LIKE '".$letter."%' ORDER BY `fname` DESC LIMIT $from, $max_results"; } else { $gender = $_POST['gender']; $letter = $_POST['letter']; $letter .= "%"; echo "Letter = " . $letter . " Gender = " . $gender ; $query = "SELECT * FROM `contacts` WHERE `gender` = '$gender' AND `fname` LIKE '$letter' ORDER BY `fname` DESC LIMIT $from, $max_results"; } $result = mysql_query($query) or die(mysql_error()); $rows = mysql_num_rows($result); echo "<table border='1'>"; echo "<tr> <th>ID</th><th>Photo</th><th>Name</th><th>Gender</th></tr>"; if ($rows > 0) { while($row = mysql_fetch_array($result)) { echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo '<a href="members_gallary.php?id='.$row['id']. '"><img src="rip_pages.php?id=' .$row['id'].'" height="35" width="45"></a>'; echo "</td><td>"; echo $row['fname']; echo "</td><td>"; echo $row['gender']; echo "</td></tr>"; } } else { echo "<tr><td colspan=\"4\">No results found!</td></tr>"; } echo "</table>"; echo "Total results = " . $rows; $total_pages = ceil($rows / $max_results); $letterstr = ($letter == "%") ? "" : "letter=" . $letter;$genderstr = ($gender == "%male") ? "" : "gender=" . $gender; echo "<p class=\"center\">Pages: "; if ($page > 1) { $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev&$letterstr&$genderstr\">«</a> "; } for($i = 1; $i <= $total_pages; $i++) { if($page == $i) { echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&$letterstr&$genderstr\">$i</a> "; } } if($page < $rows){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next&$letterstr&$genderstr\">»</a>"; } echo "</p>"; mysql_close(); ?>
  5. Hi nethnet, Thanks for the reply, I have gone back to my original script as suggested and altered the code as you pointed out. Now this works much better, i am able to select a letter then page numbers for that letter all ok, i can even select a letter and a gender once and it works fine but as soon as i select a page number it loses the letter and goes wrong, any ideas on this ?. I have included my updated script so far. Regards Tony <?php include("common.php"); // create Alphabet row for ($i=ord("A"); $i<ord("Z");$i++) { echo "<a href=\"alpha2.php?letter=" . chr($i) . "\">" . chr($i) . "</a> ¦ "; } echo "<br>"; echo "<a href=\"?\">Show All</a></p><br /> <form method=\"post\" action=\"?\"> Select Gender :<br> Male:<input type=\"radio\" value=\"male\" name=\"gender\"><br> Female:<input type=\"radio\" value=\"female\" name=\"gender\"><br> <input type=\"submit\" name=\"submit\" value=\"Search\" class=\"submit\" /> </form>"; mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); // If current page number, use it // if not, set one! if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } if(!isset($_GET['letter'])){ $letter = '%'; } else { $letter = $_GET['letter']; } if(!isset($_POST['gender'])){ $gender = "%male"; } else { $gender = $_POST['gender']; } // Define the number of results per page $max_results = 4; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); if(empty($_POST)) { $letter = $_GET['letter']; $letter .= "%"; //$sdesc = "*"; $query = "SELECT * FROM contacts WHERE fname LIKE '".$letter."%' ORDER BY fname DESC LIMIT $from, $max_results"; } else { $gender = $_POST['gender']; $query = "SELECT * FROM contacts WHERE gender LIKE '$gender' AND fname LIKE '".$letter."%' ORDER BY fname DESC LIMIT $from, $max_results"; } // Perform mysql query on only the current page number's results $result = mysql_query($query) or die(mysql_error()); //TO PRINT OUT THE DATA echo "<table border='1'>"; echo "<tr> <th>ID</th><th>Photo</th><th>Name</th><th>Gender</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo '<a href="members_gallary.php?id='.$row['id']. '"><img src="rip_pages.php?id=' .$row['id'].'" height="35" width="45"></a>'; echo "</td><td>"; echo $row['fname']; echo "</td><td>"; echo $row['gender']; echo "</td></tr>"; } echo "</table>"; //STOP PRINTING OUT THE DATA // Figure out the total number of results in DB: if(empty($_POST)) { $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM contacts ORDER BY fname DESC"),0); }else { $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM contacts WHERE gender = '$gender' ORDER BY fname DESC"),0); } echo "total pages = " . $total_results ; // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks echo "<p class=\"center\">Pages: "; // Build Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">«</a> "; } for($i = 1; $i <= $total_pages; $i++) { if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i &letter=$letter\">$i</a> "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">»</a>"; } echo "</p>"; mysql_close(); ?>
  6. Thanks for the reply dristate, I have scrapped the array and used your idea of the loop for the alphabet which is much better. I tried messing round with your code but to no avail !. I have this code so far which is basic as i am trying to build from scratch. The problem is i can select a letter and it will show all names begining with that letter from my database and when i select a gender it will show all names of that gender but what i can't achieve is select gender and letter to show only these selections from the database ? When i select a letter i get this error message. Notice: Undefined variable: gender in C:\wamp\www\public_html\alpha.php on line 33 when i select gender i get this message. Notice: Undefined variable: letter in C:\wamp\www\public_html\alpha.php on line 33 How can i get them to work together ? Regards Tony <?php session_start(); include("common.php"); // create Alphabet row for ($i=ord("A"); $i<ord("Z");$i++) { echo "<a href=\"alpha.php?letter=" . chr($i) . "\">" . chr($i) . "</a> ¦ "; } echo "<br>"; ?> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > Select Gender :<br> Male:<input type="radio" value="male" name="gender"> <br> Female:<input type="radio" value="female" name="gender"> <br><input type="submit" name="submit" value="Search" class="submit"><br> <?php if(isset($_POST['submit'])) { $gender = $_POST['gender']; $_SESSION['gender'] = $gender; echo "Selected Gender = " . $gender . "<br>"; } if (isset($_GET['letter'])) { $letter = $_GET['letter']; $_SESSION['letter'] = $letter; echo "Selected Letter = " . $letter . "<br>"; } // Connect to database $conn = mysql_connect(host,username,password) or die(mysql_error()); $db = mysql_select_db(db) or die(mysql_error()); $sql = "SELECT * FROM contacts WHERE fname LIKE '".$letter."%' AND gender = '".$gender."' ORDER BY fname"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // While there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // Echo data echo $list['id'] . " : " . $list['gender'] . " : " . $list['fname'] . "<br />"; } ?>
  7. Hi All, I have been trying to get this script to work for a while now and have realised i need some expert help here, what i am trying to achieve is select a letter from alphabet then select gender and only show results for this search but it is not quite working correct. If i search using alphabet fine all works well, but when i throw gender into the equasion it doesn't work correctly, it starts ok until i select another page number and it doesn't work then? Appreciate your help with this one. Thanks Tony <?php include("common.php"); $alphabet = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); foreach ($alphabet as $letter) { echo "<a href=\"?letter=" . $letter . "\">" . $letter . "</a> ¦ "; } echo "<a href=\"?\">Show All</a></p><br /> <form method=\"post\" action=\"?\"> Select Gender :<br> Male:<input type=\"radio\" value=\"male\" name=\"gender\"> <br> Female:<input type=\"radio\" value=\"female\" name=\"gender\"> <br><input type=\"submit\" name=\"submit\" value=\"Search\" class=\"submit\" /> </form>"; mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); // If current page number, use it // if not, set one! if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } if(!isset($_GET['letter'])){ $letter = 'a'; } else { $letter = $_GET['letter']; } if(!isset($_GET['gender'])){ $gender = "%"; } else { $gender = $_GET['gender']; } // Define the number of results per page $max_results = 4; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); if(empty($_POST)) { $letter = $_GET['letter']; $letter .= "%"; //$sdesc = "*"; $query = "SELECT * FROM contacts WHERE fname LIKE '".$letter."%' ORDER BY fname DESC LIMIT $from, $max_results"; } else { $sex = $_POST['gender']; $query = "SELECT * FROM contacts WHERE gender = '$gender' AND fname LIKE '".$letter."%' ORDER BY fname DESC LIMIT $from, $max_results"; } // Perform mysql query on only the current page number's results $result = mysql_query($query) or die(mysql_error()); //TO PRINT OUT THE DATA echo "<table border='1'>"; echo "<tr> <th>ID</th><th>Photo</th><th>Name</th><th>Gender</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['id']; echo "</td><td>"; echo '<a href="members_gallary.php?id='.$row['id']. '"><img src="rip_pages.php?id=' .$row['id'].'" height="35" width="45"></a>'; echo "</td><td>"; echo $row['fname']; echo "</td><td>"; echo $row['gender']; echo "</td></tr>"; } echo "</table>"; //STOP PRINTING OUT THE DATA // Figure out the total number of results in DB: if(empty($_POST)) { $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM contacts ORDER BY fname DESC"),0); } else { $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM contacts WHERE gender = '$sex' ORDER BY fname DESC"),0); } echo "total pages = " . $total_results ; // Figure out the total number of pages. Always round up using ceil() $total_pages = ceil($total_results / $max_results); // Build Page Number Hyperlinks echo "<p class=\"center\">Pages: "; // Build Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">«</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i &letter=$letter\">$i</a> "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">»</a>"; } echo "</p>"; mysql_close(); ?>
  8. Hi PFMaBiSmAd, Fantastic!!!, it finally works thank you so much for your help with this, I really appreaciate you helping me solve this. Regards Tony
  9. Hi PFMaBiSmAd & litebearer Thanks for your replies, I should stop doing several things at the same time, these errors were just my typos (sorry again!)even with these typos corrected i am still getting the id number colum showing ok but the image is still a blank square with a red cross inside?. Thanks Tony image2.php <?php include("common.php"); error_reporting(E_ALL); $link = mysql_connect(host,username,password) or die("Could not connect: " . mysql_error()); mysql_select_db(db) or die(mysql_error()); $sql = "SELECT id FROM photos"; $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); ?> <table border="1"><tr><td>id</td><td>image</td></tr> <?php while($row=mysql_fetch_assoc($result)){ print '<tr><td>'.$row['id'].'</td><td>'; print '<img src="image1.php?id='.$row['id'].'" height="75" width="100">'; } echo '</td></tr></table>' ?> image1.php <?php ob_start(); include("common.php"); mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); $query = mysql_query("SELECT image FROM photos WHERE id=$_GET['id']"); $row = mysql_fetch_array($query); $content = $row['image']; header('Content-type: image/jpg'); echo $content; ob_end_flush(); ?>
  10. Hi PFMaBiSmAd, Thanks for your reply, I have corrected the typo errors (sorry) not sure what you mean though regarding the $_GET issues points 1&2. I will add column to insert the image type into.I have now corrected the typos and included the corrected code below, but still i am getting the id number colum showing ok but the image is still a blank square with a red cross inside?.Is it the $_GET that is causing this ? I know when i check the properties of the images it shows image1.php?id=10 etc. so i think this looks ok?. Thanks Tony image2.php <?php include("common.php"); error_reporting(E_ALL); $link = mysql_connect(host,username,password) or die("Could not connect: " . mysql_error()); mysql_select_db(db) or die(mysql_error()); $sql = "SELECT id FROM photos"; $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); ?> <table border="1"><tr><td>id</td><td>image</td></tr> <?php while($row=mysql_fetch_assoc($result)){ print '<tr><td>'.$row['id'].'</td><td>'; print '<img src="image1.php?id='.$row['id'].'" height="75" width="100">'; } echo '</td></tr></table>' ?> image1.php <?php ob_start(); include("common.php"); mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); $query = mysql_query("SELECT image FROM photos WHERE id=$_GET['id']"; $row = mysql_fetch_array($query); $content = $row['image']; header('Content-type: image/jpg'); echo $content; } ob_end_flush(); ?>
  11. Hi Nightslyr, Thanks for the reply, errors taken on board, I have tried your function script which as you rightly say is the way forward. I have run the script you supplied (untested) and it results in a file save/download box popping up ?. Thanks Tony
  12. Hi all, Newbie here, i am having a problem to get my images to show which are stored in mysql database as a mediumblob. I get id number to print in table ut am just getting empty square with red cross in where my image should be. Is my code incorrect or is it something else? Appreciate your help with this. I have included both of the pages codes i am using. Thanks Tony image2.php <?php include("common.php"); error_reporting(E_ALL); $link = mysql_connect(host,username,password) or die("Could not connect: " . mysql_error()); mysql_select_db(db) or die(mysql_error()); $sql = "SELECT id FROM photos"; $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); ?> <table border="1"><tr><td>id</td><td>image</td></tr> <?php while($row=mysql_fetch_assoc($result)){ print '<tr><td>'.$row['id'].'</td><td>'; print '<img src="image1.php?id='.$row['id'].'height="75" width="100"">'; } echo '</td></tr></table>' ?> image1.php <?php ob_start(); include("common.php"); mysql_connect(host,username,password) or die(mysql_error()); mysql_select_db(db) or die(mysql_error()); $query = mysql_query("SELECT imgage FROM photos WHERE id={$_GET['image_id']}"; $row = mysql_fetch_array($query); $content = $row['image']; header('Content-type: image/jpg'); echo $content; } ob_end_flush(); ?>
×
×
  • 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.