Jump to content

Jarel101

Member
  • Posts

    12
  • Joined

  • Last visited

About Jarel101

  • Birthday 08/27/1990

Profile Information

  • Gender
    Male
  • Location
    Chicago, IL

Jarel101's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I'm creating a mysql keyword search on my website and I know how to search a single mysql table, my problem is I need to search 15 different tables simultaneously, they also all have the same column names. I was told I have to use JOINS or UNION JOIN but i've never used them before. How is this done? MY SQL SELECT: SELECT * FROM table1 WHERE keyword LIKE %colname% OR id LIKE %colname%
  2. I'm php newbie and I"m trying to create pagination for some DP results and I'm having some problems. I can view the pagination at the bottom of my DB results, however when I click on the numbers I remain on the same page. I'm using this 7 step pagination script: http://www.phpeasystep.com/phptu/29.html and I think my problem may be within step 7, im confused on what to do for that step, but it could be something else. I don't deal with code that often so this new to me. So my question is how do I get this script to work? <?php require_once('Connections/myconnectboi.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $maxRows_Recordset2 = 4; $pageNum_Recordset2 = 0; if (isset($_GET['pageNum_Recordset2'])) { $pageNum_Recordset2 = $_GET['pageNum_Recordset2']; } $startRow_Recordset2 = $pageNum_Recordset2 * $maxRows_Recordset2; mysql_select_db($database_myconnectboi, $myconnectboi); $query_Recordset2 = "SELECT * FROM hiphop ORDER BY id DESC"; $query_limit_Recordset2 = sprintf("%s LIMIT %d, %d", $query_Recordset2, $startRow_Recordset2, $maxRows_Recordset2); $Recordset2 = mysql_query($query_limit_Recordset2, $myconnectboi) or die(mysql_error()); $row_Recordset2 = mysql_fetch_assoc($Recordset2); if (isset($_GET['totalRows_Recordset2'])) { $totalRows_Recordset2 = $_GET['totalRows_Recordset2']; } else { $all_Recordset2 = mysql_query($query_Recordset2); $totalRows_Recordset2 = mysql_num_rows($all_Recordset2); } $totalPages_Recordset2 = ceil($totalRows_Recordset2/$maxRows_Recordset2)-1; $queryString_Recordset2 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_Recordset2") == false && stristr($param, "totalRows_Recordset2") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_Recordset2 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_Recordset2 = sprintf("&totalRows_Recordset2=%d%s", $totalRows_Recordset2, $queryString_Recordset2); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table cellspacing="0"> <tr> <td width="300"></td> <td></td> <td width="14"></td> <td width="0"></td> </tr> <?php do { ?> <tr> <td height="32" colspan="2" bgcolor="#3399CC"><?php echo $row_Recordset2['description']; ?></td> </tr> <tr> <td><img src="<?php echo $row_Recordset2['image']; ?>" width="300" height="250" border="5" /></td> <td width="300" height="250" align="center" bgcolor="#FFFFFF"><?php echo $row_Recordset2['description']; ?></td> </tr> <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> </table> <p> <?php /* Place code to connect to your DB here. */ include('Connections/myconnectboi.php'); // include your code to connect to DB. $tbl_name="hiphop"; //your table name // How many adjacent pages should be shown on each side? $adjacents = 3; /* First get total number of rows in data table. If you have a WHERE clause in your query, make sure you mirror it here. */ $query = "SELECT COUNT(*) as num FROM $tbl_name"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages['num']; /* Setup vars for query. */ $targetpage = "test.php"; //your file name (the name of this file) $limit = 4; //how many items to show per page $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; //first item to display on this page else $start = 0; //if no page var is given, set start to 0 /* Get data. */ $sql = "SELECT id FROM $tbl_name LIMIT $start, $limit"; $result = mysql_query($sql); /* Setup page vars for display. */ if ($page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 /* Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. */ $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; //previous button if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>"; else $pagination.= "<span class=\"disabled\">« previous</span>"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //close to end; only hide early pages else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">next »</a>"; else $pagination.= "<span class=\"disabled\">next »</span>"; $pagination.= "</div>\n"; } ?> <?php while($row = mysql_fetch_array($result)) { // Show if not last page } ?> <?=$pagination?> </body> </html> <?php mysql_free_result($Recordset2); ?>
  3. Just out of curiosity, how did you know it was DW produced code just by looking at it.
  4. I've created a keyword mysql search, it almost works perfect. The only problem is when I don't enter a keyword into the search form and leave it blank and click the search button, I get the data from my DB table, even though I didn't enter anything in the text box? When I enter a word that's not a keyword I just get a blank page. I would like to code it in away where when I don't enter anything and hit search or enter a keyword that I haven't added, I get a message that says "no results were found" or anything to that effect. My question is how do I do this? HERES MY CODE: SEARCH RESULTS PAGE: <?php require_once('Connections/MyConnection.p… ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_strin… ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 3; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $colname_Recordset1 = "-1"; if (isset($_GET['title'])) { $colname_Recordset1 = $_GET['title']; } mysql_select_db($database_MyConnection… $MyConnection); $query_Recordset1 = sprintf("SELECT * FROM images2 WHERE key_words LIKE %s", GetSQLValueString("%" . $colname_Recordset1 . "%", "text")); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $MyConnection) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Reco… ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-… <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table> <tr> <td></td> <td></td> <td></td> <td></td> </tr> <?php do { ?> <tr> <td><a href="viewimage.php?id=<?php echo $row_Recordset1['id']; ?>"><img src="<?php echo $row_Recordset1['Layouts']; ?>" width="300" height="250" /></a></td> <td width="300" height="250" align="center"><?php echo $row_Recordset1['Descriptions']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </body> </html> <?php mysql_free_result($Recordset1); ?>
  5. I changed the search form, but as you suspected It still won't return my db data. search page <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">'>http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="search_results.php" method="get" name="form1" id="form1"> <label for="textfield"></label> <input type="text" name="key_words" id="textfield" /> <input type="submit" name="button" id="button" value="search" /> </form> </body> </html> results page <?php require_once('Connections/test_db.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 3; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $colname_Recordset1 = "-1"; if (isset($_GET['key_words'])) { $colname_Recordset1 = $_GET['key_words']; } mysql_select_db($database_test_db, $test_db); $query_Recordset1 = sprintf("SELECT * FROM images2 WHERE key_words = %s ORDER BY id DESC", GetSQLValueString($colname_Recordset1, "text")); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $test_db) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table cellpadding="4" cellspacing="4"> <tr> <td>id</td> <td>Layouts</td> <td>Descriptions</td> <td>key_words</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Recordset1['id']; ?></td> <td><?php echo $row_Recordset1['Layouts']; ?></td> <td><?php echo $row_Recordset1['Descriptions']; ?></td> <td><?php echo $row_Recordset1['key_words']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </body> </html> <?php mysql_free_result($Recordset1); ?>
  6. That's exactly whats happening, How do I get this to work. I've followed this step by step: http://livedocs.adobe.com/en_US/Dreamweaver/9.0/help.html?content=WScbb6b82af5544594822510a94ae8d65-78ae.html but I still get no results
  7. I'm creating a image gallery and I'm about 90% complete. One of my final objectives is to create a keyword search for my image gallery. I have 4 fields in my DB, (id,layout,description,keywords) I want to be able to enter keywords into the text field to make the images with there descriptions show up. When I view my search page in firefox and type in a keyword in the text field, when the results page loads all I get is the field names in my DB table (id,layouts,desription,key_words) instead of the actual data...?? Someone told me to use LIKE instead of equal but that didn't work either. It would be greatly appreciated if someone could tell me what I'm doing wrong. HERES MY CODE SEARCH PAGE: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-…'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-… <html xmlns="http://www.w3.org/1999/xhtml">'>http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="get" action="search_results.php"> <label for="textfield"></label> <input type="text" name="textfield" id="textfield" /> <input type="submit" name="button" id="button" value="search" /> </form> </body> </html> RESULTS PAGE: <?php require_once('Connections/test_db.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_strin… ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $maxRows_Recordset1 = 3; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; $colname_Recordset1 = "-1"; if (isset($_GET['key_words'])) { $colname_Recordset1 = $_GET['key_words']; } mysql_select_db($database_test_db, $test_db); $query_Recordset1 = sprintf("SELECT * FROM images2 WHERE key_words = %s ORDER BY id DESC", GetSQLValueString($colname_Recordset1, "text")); $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $test_db) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Reco… ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-… <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <table cellpadding="4" cellspacing="4"> <tr> <td>id</td> <td>Layouts</td> <td>Descriptions</td> <td>key_words</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Recordset1['id']; ?></td> <td><?php echo $row_Recordset1['Layouts']; ?></td> <td><?php echo $row_Recordset1['Descriptions']; ?></td> <td><?php echo $row_Recordset1['key_words']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> </body> </html> <?php mysql_free_result($Recordset1); ?>
  8. Hi, I'm creating a image gallery and I'm about 90% complete. One of my final objectives is to create a keyword search for my image gallery. I have 4 fields in my DB, (id,image,description,keywords) I want to be able to enter keywords into a search and the images with there descriptions show up. I've been searching the internet and Youtube and I can't find any tutorials that I fully comprehend. I already have the keywords in my mysql. After inserting the form, text field and search button I don't really know the next step. For this project I'm using Dreamweaver Cs5, I'm not really an experienced coder I rely heavily on dreamweaver for my code, I just make minor tweaks. So if anyone has an answer to my problem please break down and simplify your answer I'm still a beginner. Thanks in advance. ps If anyone knows of any other video tutorials of this process please inform me, it would be greatly appreciated, thank you.
  9. Thanks allot, my problem is now resolved. You really made me realize how simple this was, I think I just over thought this. Again thanks
  10. Hi, I'm trying to create a web gallery something exactly like this: http: I'm about 70% done with this project, So far I have 4 fields in my DB table (ID,Image,Description,keywords). I have images in sets of 3 being displayed vertically on a webpage in descending order with pagination at the bottom as seen in the example. Here's my problem: I want to be able to click on an image and view that same image on another page, without creating a new page for every single image(as seen in the example). I here this is done by passing id parameters. To complete my project I've been following this video: I've completed everything in this video up until the 2:30 mark. At this point the instructor uses a visual query builder to complete his web gallery. At this point I get kinda confused, Do I absolutely need a visual query builder? Are there other simpler ways of completing my project that I don't know about? I want to know all I can before I purchase this qb: http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&extid=2426522 For this project I'm using Dreamweaver Cs5, I'm not really an experienced coder I rely heavily on dreamweaver for my code, I just make minor tweaks. So if anyone has an answer to my problem please break down and simplify your answer I'm still a beginner. Thanks in advance. ps If anyone knows of any other video tutorials of this process please inform me, it would be greatly appreciated, thank you.
  11. I didn't realize that site was wordpress, A more accurate example of what I'm trying to create is this: Please forgive me but I'm a super newbie at all of this, I don't understand how to use the <?php echo '<img src="' . $link_to_img . "' alt='' />"; ?> code, can you explain. How do I retrieve the link by querying the database?
  12. I'm trying to create something exactly like this: http://hypebeast.com/page/2/ I have some images on photobucket that I want to link to my mysql so I can display them dynamically on a web page...How is this done. I've heard I should store the image link in a blob field, but I've tried and it didn't allow me to right click and paste the link. I'm a beginner in php/mysql and any help would be greatly appreciated, thanks in advance.
×
×
  • Create New...