Php search script to search all values in mysql table - php

I have a table of books which has info such as bname, bauthor, bdetails...etc
I want to provide a php script to search any thing from the table ...i tried a few scripts but it didnt work ..
Also i want to provide the option to provide option of selecting category ...
if the category is not selected then also the script should run...
Can anyone help me in this please ...
..
I m trying this :
$data = mysql_query("SELECT * FROM info WHERE upper($field) LIKE'%$find%'");
$result = mysql_query($data);
if (!$result) die ("DAtabase acces faild bc : ". mysql_error());
echo " <ul class=listbk>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo " <li class=bkd><a href=details.php?bid=".$row['pid']. "> <img src=images/".$row['bname']. ".jpg />
<ul class=showcasetitle> <span> ". $row['bname'] . " </span> </ul>
<p align=center style=text-align:center; font-size:10px;> By <span> ". $row['bauthor'] . "</span></p>
</a> <p align=center style=text-align:center; color: #F00;><span class=WebRupee style=color: #F00;>₹</span> ". $row['price'] . " only !!!</span></p>
</li> " ;
}
echo " </ul> ";

<?php
$text = 'John';
$query = "SELECT * FROM `books` WHERE MATCH(`bname`,`bauthor`,`bdetails`) AGAINST ('".$text."')";
?>

Related

how do i display mysql data in marquee?

i'm trying to use a marquee to display all the data from jobs table , but some how i can't display anything at all although it connects to the database successfully .so how can i display the data using marquee ?
<html>
<body>
<div class="box" STYLE="position:absolute; TOP:110px; LEFT:1100px;height: 470px;width : 200px;padding:10px;" >
<!-- STYLE="position:absolute; TOP:170px; LEFT:980px;height: 349px;width :360px;" -->
<u><font size="3" color="white">- Jobs may inters you :</font></u>
<br>
<marquee direction="up" scrollamount="2">
<p id="boxContent">
<script>
<?php
$conn = new Mysqli("localhost", "root", "", "ISNet");
if($conn->connect_error){
die("Connection failed:".$conn->connect_error);
}
$sql = "SELECT * FROM jobs";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<br> position - ". $row["position"]. "<br> company- ". $row["company"].
" <br> address -" . $row["Address"] ."<br> description - " . $row["description"] . " <br> mail -" . $row["mail"] .
"<br>";
echo "----------------------------------";
}
} else {
echo "0 results";
}
?>
</script></p>
</marquee>
</div>
</body>
</html>
This is what you do at the start of your marquee:
<marquee direction="up" scrollamount="2">
<p id="boxContent">
<script>
You open a script tag so everything you echo out, ends up inside the script tag and will be interpreted by the browser as javascript. So you will probably see a lot of errors in the console and your text in the source code.
Just remove the opening and closing script tags and you will have yourself a very cool retro marquee :-)

How to change the "while" loop to retrieve only 3 top records from MySQL database

I set up the query to SELECT * FROM,
Then I used the while loop to print out all retrieved records and it all works fine.
But what I need is to print out only the TOP 3 of those records, is there any way to change that while loop to make it work this way.
Any help on this will be much appreciated, thx
while($row = $alerts_query->fetch_object()){
echo "<div class='panel'>
<div class='panel-heading'>
<h3 class='panel-title'>" . $row->ticket_title . " <a href='clientpanel.php?tab=dashboard=" . $row->ticketId . "' aria-hidden='true' type='button' class='close pull-right'>x</a></h3>
</div>
<div class='panel-body'>" . $row->ticket_description . "
<br />
<br />
<span style='color: #999'>Reported: " . $row->ticket_date . "</span>
</div>
</div>";
}
Do not limit in the while loop (though, it's possible). Change your SQL instead:
SELECT * FROM yourtable
Append:
SELECT * FROM yourtable LIMIT 3
If for some reason you should do it in PHP (not advised in this situation):
$i = 0;
while($row = $alerts_query->fetch_object() and $i<3) {
$i++;
// ...
}
Use:
SELECT * FROM [table] LIMIT 3
Use
SELECT * FROM table LIMIT x ORDER BY ASC
where x in your case is 3
It can achieved in many ways, using LIMIT clause is one of the approach. But following is according your scenario
$i = 1;
while ($row = $alerts_query->fetch_object()) {
if ($i > 3)
break;
echo "<div class='panel'>
<div class='panel-heading'>
<h3 class='panel-title'>" . $row->ticket_title . " <a href='clientpanel.php?tab=dashboard=" . $row->ticketId . "' aria-hidden='true' type='button' class='close pull-right'>x</a></h3>
</div>
<div class='panel-body'>" . $row->ticket_description . "
<br />
<br />
<span style='color: #999'>Reported: " . $row->ticket_date . "</span>
</div>
</div>";
$i++;
}
Try this
SELECT * FROM table LIMIT 0,3

PHP mysql_num_rows die error

I want to create one page, where users add their informations..
I allready have that page created, but my real problem its down code..
I have some kind of problem, with that part of code:
<?php
//Connect to DB
$db = mysql_connect("localhost","USER","PASS") or die("Database Error");
mysql_select_db("DB",$db);
//Get ID from request
$idstire = isset($_GET['idstire']) ? (int)$_GET['idstire'] : 0;
//Check id is valid
if($idstire > 0)
{
//Query the DB
$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire);
if($resource === false)
{
die("Eroare la conectarea cu baza de date");
}
if(mysql_num_rows($resource) == 0)
{
die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a href='http://www.wanted-web.ro'>ACASA</a>");
}
$user = mysql_fetch_assoc($resource);
echo "
<div class='main-article-content'>
<h2 class='article-title'>asd</h2>
<div class='article-photo'>
<img src='" . $user['poza'] . "' class='setborder' alt='' />
</div>
<div class='article-controls'>
<div class='date'>
<div class='calendar-date'>" . $user['data'] . "</div>
</div>
<div class='right-side'>
<div class='colored'>
<a href='' class='icon-link'><span class='icon-text'></span>Printeaza articol</a>
<a href='#' class='icon-link'><span class='icon-text'></span>Trimite prietenilor</a>
</div>
<div>
<a href='#' class='icon-link'><span class='icon-text'></span>de Cristian Cosmin D.</a>
<a href='#' class='icon-link'><span class='icon-text'></span>39 comentarii</a>
</div>
</div>
<div class='clear-float'></div>
</div>
<div class='shortcode-content'>
<p>" . $user['nume'] . " , " . $user['prenume'] . " , " . $user['varsta'] . " , " . $user['localitatea'] . "</p>
</div>
</div>
";
}
$query = "UPDATE stiri2 SET accesari = accesari + 1 WHERE idstire=\"" . $idstire . "\"";
$result = mysql_query($query) OR die(mysql_error());
?>
It's show me error from here:
if(mysql_num_rows($resource) == 0)
{
die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a href='http://www.wanted-web.ro'>ACASA</a>");
}
I really dont understand why!?
Can someone explain me?
Thank you!
mysql_query should have the second parameter as the connection which is in your case $db
$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire,$db);
if this also not works then use mysql_error to know the exact error
$row=mysql_num_rows($resource);
if($row)
{
}
else
{
mysql_error();
}
this will show you if there is problwm in mysql_num_rows
Well the problem is, that your SQL Statement does not have any results.
Please check if your database contains some rows for this idstire.
If $_GET['idstire'] is not set, you are setting $idstire to 0. Is there any entry in the table for idstire=0?
You can print your php query with $idstire replaced with its value. Take that query and execute in phpmyadmin to see the error. Also verify that row exists for the value of $idstire being used in the query.

How can i edit in php with sql

My Code -
<?php
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees ORDER BY id DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
 Echo "<img src=http://www.mywebsite.com/upload/".$info['video'] ."> <br>";  //This is the name of my Video URL in MySQL
Echo "<b>Video</b> ".$info['Video'] . "<br> "; //This is the name of my Video Name in MySQL
Echo "<b>Author</b> ".$info['Author'] . "<br> "; //This is the name of my USER in MySQL
Echo "<b>Category</b> ".$info['category'] . "<br> "; //This is the name of Video Category in MySQL
Echo "<b>Description</b> ".$info['Description'] . "<hr>"; //This is the name of Description in MySQL
}
?>
As raw output the details are coming in List like this -
Image1
Video name1
Author name1
Category1
Description1
<hr>
Image2
Video name2
Author name2
Category2
Description2
Now want to Make put <div> Tags and Tags in between the Image, Author, Video Name
How can i put ? Cuz when i edit "<br>" and insert "<div class="thumb"></div><br>"
It shows error ! - Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/servin/public_html/upload/view.php on line 14
How can i edit mysql php code so that i can add the html codes + the All details must also shows like this
you cant use double quotes by this <div class="thumb"> you should use it like that <div class='thumb'> with single quote .because you already using it with echo , try this :
<?php
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees ORDER BY id DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
echo "<div class='thumb'><img src='http://www.mywebsite.com/upload/".$info['video'] ." ' /> </div><br>"; //This is the name of my Video URL in MySQL
echo "<div class='thumb'><b>Video</b> ".$info['Video'] . "<br /> "; //This is the name of my Video Name in MySQL
echo "<div class='thumb'><b>Author</b> ".$info['Author'] . "<br /> "; //This is the name of my USER in MySQL
echo "<div class='thumb'><b>Category</b> ".$info['category'] . "<br /> "; //This is the name of Video Category in MySQL
echo "<div class='thumb'><b>Description</b> ".$info['Description'] . "<hr>"; //This is the name of Description in MySQL
}
?>
EDIT: if you want use html here better way
<?php
//Retrieves data from MySQL
$data = mysql_query("SELECT * FROM employees ORDER BY id DESC") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
?>
<div class='thumb'><img src='http://www.mywebsite.com/upload/<?php echo $info['video']; ?> ' /> </div><br />
<div class='thumb'><b>Video</b><?php echo $info['Video'] ;?><br />
<div class='thumb'><b>Author</b><?php echo $info['Author'] ;?><br />
<div class='thumb'><b>Category</b><?php echo $info['category'] ; ?><br />
<div class='thumb'><b>Description</b><?php echo $info['Description'] ; ?><hr />
<?php } ?>

PHP Gallery Problem

Ok, I have a gallery that's being populated by a database but for some reason it's not pulling entries from beyond May 31st 2011. I've scoured the code and can't find any date limitations so I'm at a loss as to why it's not pulling in any recent entries.
I've also looked through the database table and don't see any irregularities between pre May31st and more current entries.
<?php
//GALLERY PAGE
$user="USER";
$password = "PASSWORD";
$database = "GALLERY";
$hostname_portfolio ="localhost:3306";
//gets the page number from the URL
if($_GET["pageNum"]==''){
$listedNum=0;
//gets the page limit from the URL
$limit=5;
}
else{
$listedNum=$_GET["pageNum"];
//gets the page limit from the URL
$limit=$_GET["limit"];
}
//creates the list of projects and puts them into an array
$project= array();
$con = mysql_connect($hostname_portfolio,$user,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$dbcon = mysql_select_db("GALLERY", $con);
if (!$dbcon)
{
die('Could not connect: ' . mysql_error());
}
if ($dbcon)
{
}
mysql_select_db($database, $con);
$result = mysql_query("SELECT * FROM Persons ORDER BY date_uploaded DESC");
echo"<div class='clear' style='clear:both;'></div>";
$j=0;
do{
if($row['approved']=="true"){
$project[$j] =
"<div class='project-list'>
<div class='user-project'>
<div class='container'>
<div class='before-box' >
<p class='picture_state'>Before</p>
<a href='http://THEURL.com/". $row['image_path']."'>
<img src= '". $row['image_path']. "' width='400px' height='300px'/></a>
<br />
</div>
<div class='after-box'>
<p class='picture_state'>After</p>
<a href='". $row['picture_state']."'>
<img src= '". $row['picture_state']. "' width='400px' height='300px' /></a>
<br />
</div>
<div class='sidebox'>
<div class='inner-sidebox'>
<p class='date-project'>
Submitted by " . $row['FirstName'] . " " . $row['LastName']. " on " .$row['date_uploaded']. "</p>
<p> " .$row['decription']. "</p>";
if($row['ATTR1'] || $row['ATTR2']){
$project[$j] .= "<p>Used ";
if ($row['ATTR1']){
$project[$j] .= "PRODUCT2™";
if ($row['color1']){
$project[$j] .= " in " . $row['color1'];
}
if ($row['ATTR2']){
$project[$j] .= " and ";
}
}
if($row['ATTR2']){
$project[$j] .= "PRODUCT<sup>®</sup>";
if ($row['color2']){
$project[$j] .= " in " . $row['color2'];
}
}
$project[$j] .= "</p>";
}
$project[$j] .= "
</div>
</div>
</div>
<div class='clear' style='clear:both;'>
</div>
</div>
<div class='clear' style='clear:both;'>
</div>
</div>
<div class='clear' style='clear:both;'>
</div>";
$j++;
}
}
while($row = mysql_fetch_array($result));
$max=sizeof($project);
for($i=$listedNum;$i<$limit;$i++){
echo $project[$i];
}
$max=sizeof($project) - 1;
echo "<div class='bottom' style='width:170px;margin:0px auto;'>";
if($listedNum > 0){
$prevPageNum=$listedNum - 5;
$lastPage= $limit - 5;
echo "<a href='http://THEURL.com/gallery.php? pageNum=".$prevPageNum."&limit=".$lastPage."'>< Last Page </a>";
}
else{
$prevPageNum=$listedNum;
$lastPage= $limit;
}
echo" ";
if($limit <= $max){
$newPageNum=$listedNum + 5;
$nextPage= $limit + 5;
echo "<a href='http://THEURL.com/gallery.php?pageNum=".$newPageNum."&limit=".$nextPage."'> Next Page ></a>";
}
else{
$newPageNum=$listedNum;
$nextPage= $limit;
}
echo "</div>";
mysql_close($con);
?>
Im going to guess that its one of the following:
Youre server is only allowing you to pull 'x' amount of rows within each query (and that 'x' is dont at may 31st')
or theres something different with the files after may 31st. compared to the ones earlier
There's nothing in the code. It might be the way your database is configured where it only lets a certain number of results be returned and that happens to coincide with the date.
Check data in table. May be, after may 31st it was not "approved" ("approved" field was not set to something that casts to boolean TRUE)
Judging from your code - either date_uploaded is null in the records after May 31 or something else is wrong in your DB. Approved not equaling true on the offending records, for example.
Failing that, maybe it has something to do with this limitation. Try passing in a number higher than 5 and see if you get more records showing.
//gets the page number from the URL
if($_GET["pageNum"]==''){
$listedNum=0;
//gets the page limit from the URL
$limit=5;
}
else{
$listedNum=$_GET["pageNum"];
//gets the page limit from the URL
$limit=$_GET["limit"];
}

Categories