search results displaying the same thing [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a search bar and a sql database with 3 movies in
Name:Star Wars: Description: Contains the word group
Name:301: Description: Contains the word group
Name:destroyer: Description: Contains the word group
BUT when ever I search for the word "group"
I only get one result usually:
if i search for group star wars will appear 3 time.
also i know its vulnerable to sql injection but at the moment that is not an issue
here is my php code:
if(!isset($_POST['search']))
{
header("Location:index.php");
}
$search_sql="SELECT * FROM php_item WHERE Name LIKE '%".$_POST['search']."%' OR Description LIKE '%".$_POST['search']."%'";
$search_query = mysql_query($search_sql);
if(mysql_num_rows($search_query)!=0)
{
$search_rs= mysql_fetch_assoc($search_query);
}
?>
</p>
<p> Search Results</p>
<?php
if(mysql_num_rows($search_query) != 0){
do{ ?>
<p>
<?php echo $search_rs['Name']; ?>
<?php }while($searchr_rs=mysql_fetch_assoc($search_query));
} else {
echo "No Results Found";
}
?>

If this is your code, there is a typo in the while. It should be $search_rs=mysql_fetch_assoc($search_query). You have an extra 'r'.
Good Luck!

Related

Convert plain text URLs to HTML hyperlink in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a form in HTML, i ask the user to enter a url, once that happens it comes back in plain text in PHP. What i want to happen is that when they enter their URL and submit the link that they have entered will become clickable. This is the code i have. I hope this helps.
<?php
$firstname = $_POST['firstname'];
$course = $_POST['course'];
$projecturl = $_POST['projecturl'];
echo "<p>You are <span class='textblue'> $firstname</span> and ";
echo "your course at the college is: <span class='textblue'> $course </span></p> ";
echo "your project url is: <span class='textblue'> $projecturl</span></p> ";
echo "a href=’google.com’>Google</a>” .
?>
Try to use parse_url, for example:
<?php
$url = '//www.example.com/path?googleguy=googley';
var_dump(parse_url($url));
?>
If you want to search more about this code:
https://www.php.net/manual/en/function.parse-url.php
change echo statements like this
echo "<p>You are <span class='textblue'>.'"$firstname"'.</span> and ";

Get query data without foreach [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Currently I make my query like this:
<?php
function Data() {
$db = DB::getInstance();
$query = $db->query("SELECT * FROM users");
$results = $query->results();
return ($results);
}
$listdata = Data();
?>
And when I want to see my information I have something like this:
<div class="container">
<h1>Title</h1>
<hr>
<div class="row">
....
...
..
.
<?php foreach ($listdata as $v1) { ?>
<p><?=$v1->username?></p>
<?php } ?>
</div>
</div>
But if I want to put information see for example in the footer of the page I have to open a new foreach
As I can transform this code to open the query to the top of the page and simply llabar variables where I want without opening another foreach?
Even better would defeat the function, I just want to put the query and data wherever.
Thank you!
You could try echo $listdata[0]->column_name thou this will print only the first row......so to be precise use a where clause in your sql statment
Edit: It will print only the first index in the array that contains the Fetched Data

Display text on page with specific tag in wordpress [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to display a text with a specific tag in wordpress.
Ex: I have 2 tags: car and boat, and 2 text: "I have car and i want one bike", "I have boat and i am happy"
I want to display in header specific text when exist tag.
I try using tem exist in header.php but display text in all pages, not just in page where exist tag.
Ex:
<?php
$boat = term_exists('boat', 'post_tag');
if ($boat !== 0 && $boat !== null) {
echo "I have boat and i am happy!";
}
?>
If you have only two tags this will do.
<?php
if (is_tag( 'boat' )) {
echo "I have boat and i am happy!";
} elseif (is_tag('car')) {
echo "I have a car";
}
?>

PHP/SQL doesn't fetch all children from parent [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I created this code for a dropdown navigation menu. I have 2 tables in my database, one for parentitems and the other one for childitems. The parents getting out correctly, but the childitems won't.
The problem is, I only get one parent and one child at a time, or I get totally nothing.
Thanks in advance!
My code:
<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db('navigation',$con);
$query="select * from nav";
$run=mysql_query($query);
while($row=mysql_fetch_array($run)){
$m_id=$row['m_id'];
$m_title=$row['m_title'];
$child_query="select * from nav_child where parent_id='$m_id'";
$run_child=mysql_query($child_query);
while($row_child=mysql_fetch_array($run_child)) {
$child_id=$row_child['nav_id'];
$child_title=$row_child['child_title'];
echo"<ul>
<li><a href='menu.php'>$m_title</a>
<ul>
<li><a href='menu.php'>$child_title</a></li>
</ul>
</li>
</ul>";
}
}
?>
You need to split your html
while(mainquery) {
echo '<ul>' <-----note the location
while (subquery) {
echo '<li>subquery 1 stuff</li>'
}
echo '</ul>' <-----note the location
}
You're outputting it entirely in your subquery section, so EVERY child row gets its own complete <ul><li>...</li></ul> tag set.

how to set li active class using php if clicked [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hello I would like to set li active in PHP: if it's clickable, then it's active, if not then it's not active. I've tried several ways but nothing works. Here's my code :
<ul>
<?php
$sql = mysql_query("SELECT * FROM pages WHERE isRoot='1' ORDER BY pageID");
while ($row = mysql_fetch_object($sql))
{
echo "<li>$row->pageTitle </li>";
}
?>
</ul>
The easiest way is to us a GET parameter.
The link to your site than will be index.php?pageID=11 - in this case 11 stands for die pageID 11
in your while loop you have to check if this site is the active one
if($row->pageID == $_GET['pageID'])
{
//active li
echo "<li class="active">$row->pageTitle </li>";
}
else
{
//normal li
echo "<li>$row->pageTitle </li>";
}
You could do the same with PageTitle too

Categories