Jump to content

phatuis

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

phatuis's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I am looking for some help. What I am hoping to do, is say if in the search box, R is put in, then the script will run a command where it searches the database, where say in name, the first letter is R. However, if someone submits RY, then it would search NAME where it begins with RY. Is this possible? EDIT: Nevermind
  2. Hello, say: $explode = explode(" ", $data) I want to see if a variable is found in the data when exploded, and if found, return 1 piece of code, if no found another piece of code.
  3. I worked that one out about 10 minutes after I posted my last post, but thanks anyway guys.
  4. If this cant be fixed, I have an idea, maybe a while loop with say a variable called idnum, which for each loop goes up 1, then I set idstart as deleteid + idnum, so then it loops upwards until the last id?
  5. I'll break it down $idstart is what the id starts as, like for the first foreach loop the id will be $deleteid + 1, because it is in the first loop, then on the second it is $deleteid + 2. $idupdate is simply $idstart - 1, which then lowers each id by one after deletion.
  6. Wouldnt it be set in the foreach loop, $array AS $idnum?
  7. All Code: <?php include("global.php"); connect(); $sql = "SELECT * FROM `banners` WHERE admin='1' AND username='".$session_username."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 1) { $sql2 = "SELECT * FROM `banners`"; $res2 = mysql_query($sql2) or die(mysql_error()); if(isset($_GET['delete'])) { $deleteid = $_GET['delete']; if(!isset($_GET['sure'])) { echo "<center>Are you sure you want to delete this data?<br><br>"; echo "<a href='admin.php?delete=".$deleteid."&sure=1'>Yes, I am sure</a<br>"; echo "<a href='admin.php'>No, I am not.</a></center>"; }else { $sqldelete = "DELETE from `banners` WHERE id='".$deleteid."'"; $resdelete = mysql_query($sqldelete) or die(mysql_error()); $upsql = "SELECT * FROM `banners` WHERE id > '".$deleteid."'"; $upres = mysql_query($upsql) or die(mysql_error()); $array[] = $upres; foreach($array AS $idnum) { $idstart = $deleteid + $idnum; $idupdate = $idstart - 1; $sqlupdate = "UPDATE `banners` SET id='".$idupdate."' WHERE id='".$idstart."'"; $sqlres = mysql_query($sqlupdate); } echo "You have successfully deleted the item with an ID of ".$deleteid."!"; } } else { while($assoc = mysql_fetch_assoc($res2)) { $id = $assoc['id']; $username = $assoc['username']; $sitename = $assoc['sitename']; $bannerurl = $assoc['bannerurl']; $url = $assoc['url']; echo "<center><table border='1'>"; echo "<tr><td>".$username."</td><td>".$sitename."</td><td>".$bannerurl."</td><td>".$url."</td><td><a href='admin.php?delete=".$id."'>Delete</a></td></tr>"; echo "</table></center>"; } } }else { die("You do not have permission to access this area"); } ?>
  8. When I click delete next to the data on the main page, the deleteid is found using GET, so like if the extension is admin.php?delete=1 , then the id being deleted is 1
  9. What I am trying to do, is say I have 1 piece of data with id 1, one with id 2, and one with 3. Using this code, I can successfully delete the selected data by id, but also what I want to do is for every id above the one deleted, I want to make them go down by 1, like the one with id of 2 would go to 1, and the one with id of 3 would go to 2, the code below is what I have tried, and been unsuccessful This is my code so far: $sqldelete = "DELETE from `banners` WHERE id='".$deleteid."'"; $resdelete = mysql_query($sqldelete) or die(mysql_error()); $upsql = "SELECT * FROM `banners` WHERE id > '".$deleteid."'"; $upres = mysql_query($upsql) or die(mysql_error()); $array[] = $upres; foreach($array AS $idnum) { $idstart = $deleteid + $idnum; $idupdate = $idstart - 1; $sqlupdate = "UPDATE `banners` SET id='".$idupdate."' WHERE id='".$idstart."'"; $sqlres = mysql_query($sqlupdate); } echo "You have successfully deleted the item with an ID of ".$deleteid."!";
×
×
  • 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.