I have two scripts that each work fine by themselves. One is a search script with a variable that depends on what people search for. That will display results, but they are in a single column. I want to be able to paginate the results and have 4 columns across. I have a script that will do the pagination and it works by itself. What I want is the search results to be displayed in the 4 columns across with the pagination. I'm not familiar enough with programming to merge these two. Can anyone help me out?
Script 1 is the search form.
Code: <?php
include 'myconnectinfo.php';
$cxn = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
mysql_select_db($database);
// $database = "mydatabase_name";
$keyword= $_POST['keyword'];
$upperKeyword = strtoupper($keyword);
$query = "(SELECT * FROM cjstores WHERE upper(NAME) like '%$upperKeyword%' ORDER BY NAME)";
$result = mysql_query($query)
or die ("Couldn't execute query.");
if(! $result){
$message = "no results";
}
$message = "Sorry, no matching results.";
$found = mysql_num_rows($result);
if($found == 0){
echo "No products were found with that name. Please try another name.";
}
/* Display results in a table */
echo "<table cellspacing='10'>";
echo "<tr><td colspan='3'><hr /></td></tr>";
while($row = mysql_fetch_assoc($result))
{
extract($row);
echo "<TABLE cellpadding='10' width='40%'><tr>n
<td width='200'><img src='$IMAGEURL' border ='0' alt='$NAME'><br clear='all'><P><font size='2'>
<a href='$BUYURL'>$NAME</a></td>n
<td width='100'></td>n
</tr>n";
echo "<tr><td colspan='2'><hr /></td></tr>n";
}
echo "</table>n";
?>
SCRIPT 2 displays based on my sql query - I want this to be base on the user input?
Code: <?php
include('myconnectinfo.php');
$database = "giftidea_gifts";
$cxn = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
mysql_select_db($database);
$conn = mysql_connect('localhost','user','pass') or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db('databasename',$conn) or trigger_error("SQL", E_USER_ERROR);
// find out how many rows are in the table
$sql = "SELECT COUNT(*) FROM cjstores WHERE ADVERTISERCATEGORY LIKE '%Necklaces & Pendants%'";
$result = mysql_query($sql, $cxn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 4;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if
// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
// set current page to first page
$currentpage = 1;
} // end if
// the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT BUYURL, IMAGEURL, NAME, DESCRIPTION FROM cjstores WHERE ADVERTISERCATEGORY LIKE '%Necklaces & Pendants%' LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
define ("NUMCOLS", 4);
$res = mysql_query("SELECT BUYURL, IMAGEURL, NAME, DESCRIPTION FROM cjstores WHERE ADVERTISERCATEGORY LIKE '%Necklaces & Pendants%'");
$count = 0;
echo "<table class='mytable' width='60%' cellpadding='0' cellspacing='0'>";
while ($list = mysql_fetch_assoc($result))
{
if ($count % NUMCOLS == 0) echo "<tr>n"; # new row
echo " <td align='center' valign='top' class='mytable'><a href=". $list['BUYURL'] . " class='mypage'><img src=" . $list['IMAGEURL'] . " border='0' alt='NAME'>
<font face='arial' size='1'>" . $list['NAME'] . "</a>
<table><tr><td><font size='1'></td><tr></table></td>";
$count++;
if ($count % NUMCOLS == 0) echo "</tr>n"; # end row
}
# end row if not already ended
if ($count % NUMCOLS != 0) {
while ($count++ % NUMCOLS) echo "<td> </td>";
echo "</tr>n";
}
echo "</table>";
/****** build the pagination links ******/
// range of num links to show
$range = 4;
// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
// get previous page num
$prevpage = $currentpage - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $currentpage) {
// 'highlight' it but don't make a link
echo " [<b>$x</b>] ";
// if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
// echo forward link for lastpage
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
Thank you
PHP, Arrays & A Lot Of Confusion
I've been doing basic PHP work on sites for a few years now, but I've never been tempted to learn how the ARRAY function worked, nor in what instances to use it. Now I've stumbled upon the jCarousel
Form Help
Here is the form:Line number On/Off | Expand/Contract<? include("../include/session.php"); ?> <?php if ($submit) { $sql = "UPDATE productimages
PHP, jAVASCRIPT setting input values, why isn't it working?
Hi:I am calling this javascript:<script language="javascript">function set_item_values(x){document.forms.form1.GetElementById(x).value =
extending tidy
I have problem with type-hinting and extending tidy. This code creates error:Code: class cMyTidy extends tidy{ public $tralala;}$oMyTidy = new cMyTidy();doSomething($oMyTidy);function
Save file by click
Hello. I'm not understand how to save file from page. I'd like make link to file with save ability.<?phpchdir('upload/');foreach (glob("*.*") as $filename) { $uploadfile =
radio button reamains checked
Hello i'm trying to keep the state off my radio buttons so it shows which ones where clicked after the submit button is clicked im new to this so bare with me.heres my code <?phpforeach($_POST
Query output more than expected
$query=mysql_query("SELECT * FROM players, communities, divisions WHERE dob BETWEEN '{$start_date}' AND '{$end_date}' and communities.id=players.community order by communities.community,
finding key position of specified value in multi-dimensional array
Code: $openedfile = fopen($tfc_file4, "r");$rc = 1;while(!feof($openedfile)){$rc++;$hold[$rc] = explode("|" , trim(fgets($openedfile)));}fclose($openedfile);How can I loop through
Creating web pages by php
Hello again,I was just wondering us there a way to use a php script to create a new web page. I guess the best example is something like YouTube where when a video is uploaded, it's assigned a new
Simple AND question
Hello,I've got following code:Code: if(strpos($row[13],"http://")!==false) $info['results'][$num]['player']="PREVIEW"; else