Stuck with my search script

Hello i wanted to have same build as apelsinen.com/?p=start but now when i search i get many bugs! i don’t know how to solved it can anyone help me out? The links make them self x5
I just want it working normal! Plus when i search after something as not exist it show all links
apelsinen.com/?p=start

search.php
[PHP]

<?php if(isset($_POST['submit'])){ ?> <?php $date = date('Y-m-d'); $link_table = ""; $updaters =""; $updaters = array(); $sql = "SELECT `upp_links`.`link`, `upp_links`.`besk`, `upp_links`.`date`, `upp_links`.`type`, `upp_links`.`click`, `upp_links`.`filter`, `upp_links`.`cat`, `users`.`user`, `upp_links`.`updater_id`, upp_links.id FROM `upp_links`, `users` WHERE `besk` LIKE '%$search%' ORDER BY id DESC"; //$sql = "SELECT * FROM `upp_links` ORDER BY `upp_links`.`date` DESC LIMIT 0 , 30"; //$sql = "SELECT * FROM `upp_links` WHERE `id` = 1 AND `date` = \'2012-04-19\' LIMIT 0, 30 ";

$result = mysql_query($sql);
while($rad = mysql_fetch_array($result))
{
$type = $rad[‘type’];
$cat = $rad[‘cat’];
$updater = $rad[‘updater_id’];
if ($rad[‘filter’] == false)
{
$filter = “images/filter/green.png”;
}
else
{
$filter = “images/filter/red.png”;
}
$link_table .= ‘

’;
if (empty($updaters[$updater]))
{ $updaters[$updater] = 0;}
$updaters[$updater] = $updaters[$updater]+1;
}
foreach ($updaters as $key => $value) {
$sql = “SELECT user, id FROM users WHERE users.id = {$key}”;
$result = mysql_query($sql);
if (!$result) { die('Invalid query: ’ . mysql_error()); }
while ($rad = mysql_fetch_array($result)){
    //var_dump($rad);
    echo $rad[1] . "::" . $rad[0] . "<br><br>";
    }
    //echo $value;

}
// Visa vilka som uppdaterat och hur många
//var_dump($updaters);
//echo $updaters;
echo $link_table;
?>

Typ Länk Filter Tipsare Datum
<img src="’.$type_nr[$type].’" ’.$rad[‘besk’].’ <img src="’.$filter.’" width="10"height=“10”> ’.$rad[‘user’].’ ’.$rad[‘date’].’
<?php } ?>[/PHP]

With a quick look through the code you posted you search for %$search% but you don’t set $search anywhere. This results in a “LIKE ‘%%’” in your query and that correctly replies with the entire content of the table.

What you need to do is fill $search with the value you posted via your search form.

I have no information about the structure of your database, but you don’t only pull from upp_linksbut also from users, you may want to check that too.

BTW. What are you trying to do here?
[php]
$updaters ="";
$updaters = array();
[/php]

Hope that helps :smiley:

I’m not so good in .php i have only copy and paste this but here is a picture from database.

http://2.imgland.net/Fgq5H.jpg

Ah, thanks. I’m more interested in the ‘users’ table. But… do you understand what you’re doing? I mean, can you read the PHP?
The first step is to fill $search.

The client fills it in here:

<input type="text" name="search" placeholder='Skriv in sökord...'/>

In the following code you don’t ever read that value everywhere.
Somewhere in your code you need the line:
[php]$search = $_POST[‘search’]; [/php]
From that point on what your users typed in the form ( in the input named ‘search’ ) is available to you in $search. ( Note, it’s not checked, it could be anything )

Thanks for an image of your databasemanager. It’s not very helpful to me. What I meant was, look in the ‘users’ table and see if there’s a field named ‘besk’ there too. Otherwise the query needs to be rewritten. ( or at least the ‘users’ part of the query yields no results ) ( made me laugh, like asking :“What kind of car do you have” and get a picture of a wheel as an answer :wink: )

Errormessages and warnings have useful information, they point to parts of the code where things go wrong. It’s always a good startingpoint for debugging.
Also, comment out all the code you don’t understand and then line-by-line uncomment it to see what it does and if the problem is inthere. Trying to grok a large block of code can be a bit disorienting.

Good luck! ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service