Jump to content

Making a file browsing script + page stepping !!! WTF


Recommended Posts

It really isn't working too well, so hey, I tried this out...

 

I made a script to query the name field in teh database of files for any file starting with a single letter chosen. "X%" would search for everythign beginning with an X. (in mysql terms a % is a wildcard*) My current code can be found below, it sucks balls, yes, but I could not think of a better way to do it.

 

It currently searches and returns no results no matter what, although all of my files currently in the database do not have capital letters so maybe iI should search for both the upercanse and lowercase letters for an input? (X and x). But how would I do this? I am using RANGE to make the HTML inks for it, and I THINK I am doing the page stepping properly by saying LIMIT (perpage),(startnum);

 

<?PHP
if (!empty($_GET['go'])) {
 $mysearch =$_GET['go'];
 $mysearch = trim($mysearch);
  if (!$mysearch || $mysearch=='')
    html('Search, No Results!','No Results Were Returned!');
  if (strlen($mysearch)>2)
    html('Hacking Attempt Detected, THIS IS NOT THE SEARCH!.');

 /* MYSQL CONNECTION */
 mysql_connect(localhost,'root','');

$page = 1 + $_GET['p'] * 25;

$sql = "SELECT * FROM `*`.`files` ";
$sql.= "WHERE `Name` LIKE '$mysearch%' LIMIT 25,$page";

  $result = mysql_query($sql);
  if (!$result)
     html('No Results!','No Results Were Returned!');

$RET = '<font size="3">Returned '.$num_books.' Results</font>
 <TABLE width="95%">
 ';

while(list($ID,$Name,nul,$Description,nul,$Downloads)= mysql_fetch_row($result)) { $RET.= "
 <TR><TD><a href='./FORM/Files.php?download&id=$ID'>$Name</a></TD><TD>$Description</TD><TD>$Downloads</TD></TR>
 ";
}
$RET.= '</TABLE>';
}

$REM = $RET; $REE='';

foreach (range('1', '9') as $letter) {
 $REE.= '<A HREF="?go='.$letter.'">'.$letter.'</A> ';
}
foreach (range('A', 'Z') as $letter) {
 $REE.= '<A HREF="?go='.$letter.'">'.$letter.'</A> ';
}

$RET = $REE.$REM;

echo $RET;

?>

 

So , even though my code SUCKS, why doesn't it work?

BTW, I am aware that I have not outputted the page selection dropdown yet.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.