Jump to content

mahenda

Members
  • Posts

    146
  • Joined

  • Last visited

Everything posted by mahenda

  1. create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that
  2. Now i want to insert reply on replies table i.e INSERT INTO replies(reply,commentId,userId) VALUES ('reply here',Id of the current comment, id of the current user); i'm using $_SESSION['userId'] to get current user info.but how to get id of the current comment where the current user want to comment any idea please
  3. CREATE TABLE posts ( postId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, title VARCHAR(255) NOT NULL, author VARCHAR(24) NOT NULL, description TEXT NOT NULL, createdAt TIMESTAMP, PRIMARY KEY (postId) ); CREATE TABLE comments( commentId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, comment TEXT NOT NULL, postId INT(11), userId INT(11), createdAt TIMESTAMP, PRIMARY KEY (commentId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (postId) REFERENCES posts(postId) ); CREATE TABLE replies ( repId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, reply TEXT NOT NULL, userId INT(11), commentId INT(11), createdAt TIMESTAMP, PRIMARY KEY (repId), FOREIGN KEY (userId) REFERENCES users(userId), FOREIGN KEY (commentId) REFERENCES comments(commentId) ); CREATE TABLE users ( userId INT(11) NOT NULL UNIQUE AUTO_INCREMENT, userName VARCHAR(100) NOT NULL,, email VARCHAR(100) NOT NULL, PRIMARY KEY (userId) ); how to retrive userName,comment, and createdAt from users and comments table while I have used userId as a Foreign key on the comment table if it isn't correct, correct me please
  4. ok let me try your suggestion , after that i'll return back, but after clicking page link and looking on the url bar this is showing http://localhost/movies_dbase/search.php?page=1 with no data on the page
  5. i have turned on the display_errors in php.in and then paste the error_reporting( E_ALL ); in my script but nothing shown xampp control panel v3.2.2 PHP version: 7.2.11
  6. <?php if(isset($_GET['submit'])){ $names = $_GET['search']; $escapeString = mysqli_real_escape_string($conn, $names); if(!empty($escapeString)){ $resultPerPage = 8; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; } $startPage = ($page-1) * $resultPerPage; $sql = "SELECT * FROM movies WHERE name LIKE '%$escapeString%' OR producer LIKE '%$escapeString%' LIMIT ".$startPage.",".$resultPerPage; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)){ echo ' <div> <span>'.$row['name'].'</span> <span>'.$row['producer'].'</span> <p>'.$row['shortDescription'].'</p> </div> '; } echo '<ul class="pagination">'; if ($page == 1) { echo '<li class="disabled"><a href="#">First</a></li> <li class="disabled"><a href="#">«</a></li>'; } else { $linkPrev = ($page > 1) ? $page - 1 : 1; echo '<li><a href="search.php?page=1">First</a></li> <li><a href="search.php?page='.$linkPrev.'">«</a></li>'; } $cSql = "SELECT COUNT(*) FROM movies WHERE name LIKE '%$escapeString%' OR producer LIKE '%$escapeString%'"; $cResult = mysqli_query($conn, $cSql); $row = mysqli_fetch_row($cResult); $totalRecords = $row[0]; $noOfpage = ceil($totalRecords/ $resultPerPage); $linkNumber = 7; $startNumber = ($page > $linkNumber) ? $page - $linkNumber : 1; $endNumber = ($page < ($noOfpage - $linkNumber)) ? $page + $linkNumber : $noOfpage; for ($i = $startNumber; $i <= $endNumber; $i++) { $linkActive = ($page == $i) ? 'class="active"' : ''; echo '<li '.$linkActive.'><a href="search.php?page='.$i.'">'.$i.'</a></li>'; } if ($page == $noOfpage) { echo '<li class="disabled"><a href="#">»</a></li> <li class="disabled"><a href="#">Last</a></li>'; } else { $linkNext = ($page < $noOfpage) ? $page + 1 : $noOfpage; echo '<li><a href="search.php?page='.$linkNext.'">»</a></li> <li><a href="search.php?page='.$noOfpage.'">Last</a></li>'; } echo '</ul>'; } else { echo ' <div class="head"> <h6 class="ml-0"> RESULTS REPORT:</h6> </div>'; echo '<span> The keyword </span><span class="text-warning"> '.$escapeString.' </span><span> is not available in our database </span>'; } } else { echo 'You have to Enter movie name or producer'; } ?> -
  7. let's us leave the issue of escape string first i'll implement it later , i'm already changed the sql statement as ginerjm said, but the issue here is when you click the pagination number it show the first page only and the remaining page link show blank page i want to match the returned results with the page please try testing my code if i don't understand show me just an example or use my code to show me any problem you think it may have as you quoted sql line
  8. //the problem i'm experiencing here is the 1,2 ,3.... pages are black how to solve this help me if there is any mistake and how to get the url of the logical page and how http_build_query() work <?php if(isset($_GET['submit'])){ $names = $_GET['search']; $escapeString = mysqli_real_escape_string($conn, $names); if(!empty($escapeString)){ $resultPerPage = 8; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; } $startPage = ($page-1) * $resultPerPage; $sql = "SELECT * FROM movies WHERE name LIKE '%".$escapeString."%' OR producer LIKE '%".$escapeString."%' LIMIT ".$startPage.",".$resultPerPage; $result = mysqli_query($conn, $sql); while($row = mysqli_fetch_assoc($result)){ echo ' <div> <span>'.$row['name'].'</span> <span>'.$row['producer'].'</span> <p>'.$row['shortDescription'].'</p> </div> '; } echo '<ul class="pagination">'; if ($page == 1) { echo '<li class="disabled"><a href="#">First</a></li> <li class="disabled"><a href="#">&laquo;</a></li>'; } else { $linkPrev = ($page > 1) ? $page - 1 : 1; echo '<li><a href="search.php?page=1">First</a></li> <li><a href="search.php?page='.$linkPrev.'">&laquo;</a></li>'; } $cSql = "SELECT COUNT(*) FROM movies WHERE name LIKE '%".$escapeString."%' OR producer LIKE '%".$escapeString."%'"; $cResult = mysqli_query($conn, $cSql); $row = mysqli_fetch_row($cResult); $totalRecords = $row[0]; $noOfpage = ceil($totalRecords/ $resultPerPage); $linkNumber = 7; $startNumber = ($page > $linkNumber) ? $page - $linkNumber : 1; $endNumber = ($page < ($noOfpage - $linkNumber)) ? $page + $linkNumber : $noOfpage; for ($i = $startNumber; $i <= $endNumber; $i++) { $linkActive = ($page == $i) ? 'class="active"' : ''; echo '<li '.$linkActive.'><a href="search.php?page='.$i.'">'.$i.'</a></li>'; } if ($page == $noOfpage) { echo '<li class="disabled"><a href="#">&raquo;</a></li> <li class="disabled"><a href="#">Last</a></li>'; } else { $linkNext = ($page < $noOfpage) ? $page + 1 : $noOfpage; echo '<li><a href="search.php?page='.$linkNext.'">&raquo;</a></li> <li><a href="search.php?page='.$noOfpage.'">Last</a></li>'; } echo '</ul>'; } else { echo ' <div class="head"> <h6 class="ml-0"> RESULTS REPORT:</h6> </div>'; echo '<span> The keyword </span><span class="text-warning"> '.$escapeString.' </span><span> is not available in our database </span>'; } } else { echo 'You have to Enter movie name or producer'; } ?> help @Barand @ginerjm@cyberRobot@mac_gyver
  9. i tried to follow some instruction here but i don't achieve ,i'm getting into trouble I know you helped me on this it will be better , if someone can show me an example with source code according to mac_gyver @mac_gyver @Barand @cyberRobot and others pleaseeeeeeeeeee! i cant handle it without some snippet help help me guys
  10. //according to mac_gyver i'm trying step 1 here help for any mistakes <?php if(isset($_GET['submit'])){ include_once('conn.php'); $names = $_GET['search']; $escapeString = mysqli_real_escape_string($conn, $names); if($escapeString !=""){ $sql = "SELECT name,poducer FROM movies WHERE name LIKE '%.$escapeString.%' OR producer LIKE '%.$escapeString.%' "; $result = mysqli_query($conn, $sql); if(mysqli_num_rows($result) >0){ echo ' <div class="head"> <h6 class="ml-0"> RESULT RELATED WITH: <span class="text-success">'.$escapeString.'</span></h6> </div>'; while($row = mysqli_fetch_assoc($result)){ echo '<div> <span>'.$row['name'].'</span> <span>'.$row['producer'].'</span> </div> '; } } else{ echo ' <div class="head"> <h6 class="ml-0"> RESULTS REPORT:</h6> </div>'; echo '<span>The term </span><span class="text-warning"> '.$escapeString.' </span><span> is not available in our database </span><br><span> try <a href="#" style="text-decoration:none;">Advanced Search</a> </span>'; } } else{ echo '<span>you have to enter something</span>'; } } ?> //updated
  11. //according to mac_gyver i'm trying step 1 here help for any mistakes <?php if(isset($_GET['submit'])){ include_once('conn.php'); $names = $_GET['search']; $escapeString = mysqli_real_escape_string($conn, $names); if($escapeString !=""){ $sql = "SELECT name,poducer FROM movies WHERE name LIKE '%.$escapeString.%' OR producer LIKE '%.$escapeString.%' "; $result = mysqli_query($conn, $sql); if(mysqli_num_rows($result) >0){ echo ' <div class="head"> <h6 class="ml-0"> RESULT RELATED WITH: <span class="text-success">'.$escapeString.'</span></h6> </div>'; while($row = mysqli_fetch_assoc($result)){ echo '<div> <span>'.$row['name'].'</span> <span>'.$row['producer'].'</span> </div> '; } } else { echo ' <div class="head"> <h6 class="ml-0"> RESULTS REPORT:</h6> </div>'; echo '<span>The term </span><span class="text-warning"> '.$escapeString.' </span><span> is not available in our database </span><br><span> try <a href="#" style="text-decoration:none;">Advanced Search</a> </span>'; } else{ echo '<span> Mh! You have to Enter search term'; } } } ?>
  12. //i want to put all result into pagination help me how to structure the php code check the first search php code an the second pagination codes //search php code if(isset($_GET['submit'])){ include_once('conn.php'); $movieName = $_GET['search']; $escapeString = mysqli_real_escape_string($conn, $movieName ); if($escapeString !=""){ $sql = "SELECT name, producer FROM movies WHERE name LIKE '%.$escapeString.%' OR producer LIKE '%.$escapeString.%' "; $result = mysqli_query($conn, $sql); if($row = mysqli_fetch_assoc($result)){ echo ' <div> <span>'.$row['name'].'</span> <span>'.$row['producer'].'</span> </div> '; } else { echo "<span> no such term in our database! </span>"; } else { echo "<span> you have to enter search term in the field! </span>"; } ?> //pagination php code $limit = 8; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; } $startPage= ($page-1) * $limit; $sql = "SELECT COUNT(moviesId) FROM movies"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_row($result); $totalRecords = $row[0]; $totalPages = ceil($totalRecords / $limit); $pageLink = "<ul class='pagination'>"; for ($i=1; $i<=$totalPages; $i++) { $pageLink .= "<li><a href='search.php?page=".$i."'>".$i."</a></li>"; } echo $pageLink . "</ul></nav>";
  13. so i have to use mysqli_fetch_assoc and how t can i highlight the search text using tis codes please i need example i'm not an an experienced developer
  14. <?php //I added name="submit" in the form now my cde are //let's start with this part before pagination is this correct and secured ?! help me with example if(isset($_GET['submit'])){ include_once('conn.php'); $movieName = $_GET['search']; $escapeString = mysqli_real_escape_string($conn, $movieName ); if($escapeString !=""){ $sql = "SELECT name, producer FROM movies WHERE name LIKE '%".$escapeString."%' OR producer LIKE '%".$escapeString."%' "; $result = mysqli_query($conn, $sql); if($rows = mysqli_fetch_all($result)){ echo ' <div> <span>'.$rows['name'].'</span> <span>'.$rows['producer'].'</span> </div> '; } else { echo "<span> no such term in our database! </span>"; } else { echo "<span> you have to enter search term in the field! </span>"; } ?> look at that guys
×
×
  • 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.