PJStew
08-10-2006, 11:30 AM
I'm trying to make a simple search for my images, so you can seach by username I would also like if posible, to be able to search be style eg. (Trials, Freestyle, ect...) the code have done so far, will display 1 image by the user, but then I can't get it to go to the next. Plus I can only search by username.
<body>
<form action="<?php $PHP_SELF ?>" name="search" method="post">
<input type="text" name="username" />
<input type="submit" value="Search" />
</form>
<?php
$username = $_POST['username'];
$conn = mysql_connect("localhost","user","password")
or die("Could not connect");
$rs = mysql_select_db("images",$conn)
or die("Could not select database");
$sql2 = "SELECT COUNT(*) as `count` FROM uploaded_images WHERE user_name = '$username'";
$result = mysql_query($sql2) or die();
$row = mysql_fetch_array($result);
$numrows = $row['count'];
$p = (isset($_GET["pic"]) and is_numeric($_GET["pic"]) and ($_GET["pic"] > 0) and ($_GET["pic"] <= $numrows))
? $_GET["pic"]
: $numrows ;
$sql1 = "SELECT * FROM uploaded_images WHERE user_name = '$username' ORDER BY id LIMIT 1 OFFSET ".($p - 1);
$result = mysql_query($sql1) or die();
$r = mysql_fetch_assoc($result);
if($p)
{
echo "<a href=\"?p=exhibition&filename=" . ($p - 1) . "\" id=\"A3\">PREVIOUS</a> ";
echo " <a href=\"?p=exhibition&filename=" . ($p + 1) . "\" id=\"A2\">NEXT</a>";
}
?>
<?php echo '<div id="EXHIBITION"><img src="'.$r['filename'].'" alt=" "></div>'; ?>
</body>
</html>
Any ideas?
<body>
<form action="<?php $PHP_SELF ?>" name="search" method="post">
<input type="text" name="username" />
<input type="submit" value="Search" />
</form>
<?php
$username = $_POST['username'];
$conn = mysql_connect("localhost","user","password")
or die("Could not connect");
$rs = mysql_select_db("images",$conn)
or die("Could not select database");
$sql2 = "SELECT COUNT(*) as `count` FROM uploaded_images WHERE user_name = '$username'";
$result = mysql_query($sql2) or die();
$row = mysql_fetch_array($result);
$numrows = $row['count'];
$p = (isset($_GET["pic"]) and is_numeric($_GET["pic"]) and ($_GET["pic"] > 0) and ($_GET["pic"] <= $numrows))
? $_GET["pic"]
: $numrows ;
$sql1 = "SELECT * FROM uploaded_images WHERE user_name = '$username' ORDER BY id LIMIT 1 OFFSET ".($p - 1);
$result = mysql_query($sql1) or die();
$r = mysql_fetch_assoc($result);
if($p)
{
echo "<a href=\"?p=exhibition&filename=" . ($p - 1) . "\" id=\"A3\">PREVIOUS</a> ";
echo " <a href=\"?p=exhibition&filename=" . ($p + 1) . "\" id=\"A2\">NEXT</a>";
}
?>
<?php echo '<div id="EXHIBITION"><img src="'.$r['filename'].'" alt=" "></div>'; ?>
</body>
</html>
Any ideas?