m5638829 Posted October 12, 2009 Share Posted October 12, 2009 Hello, I am trying to code a project and ran into a brick wall with one of my pages. I am pretty new at php/mySQL and can not figure this out. Now I know that you are not going to sit there and type my whole script out for me. That is NOT what I am asking. I need pointers, links to tutorials, or whatever help you can get me. I appreciate it very much! First off, I am recoding a site I created a little while ago in pure HTML to php. This site is a help wanted site and it has had massive amounts of hits and requests to put up listings. I have the pages to submit a listing, write that to the database, and one to show the results in a raw format. However, I am running into two problems. One is that I want to code the main page to just be a mysql query. This means that I want it to show just the company name and position available, then have a button to click to get the rest of the info about the job listing in a separate pop-up window. I can not seem to find code, tut or anything of the like about this. Second problem, in my raw data results (plan table showing database contents) I need a link that will remove the entry. I have tried a couple of scripts and messed up my code further. I was wondering if anyone knows of something that describes this is great detail. It is all in a table. Here is some of my code for the table with the DB contents: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View All Job Listings</title> </head> <body> <?php require 'dbconnect.inc'; mysql_select_db("coushatta", $con); $result = mysql_query('SELECT * FROM jobs', $con); echo "<table border='1'> <tr> <th>ID</th> <th>Business Name</th> <th>Contact Name</th> <th>Phone Number</th> <th>Fax Number</th> <th>Email Address</th> <th>Position Open</th> <th>Open</th> <th>Filled</th> <th>Closed</th> <th>Listing Content</th> <th>Delete?</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td><a href='" . $row['ID'] . ".html'>" . $row['business_name'] . "</a></td>"; echo "<td>" . $row['contact_name'] . "</td>"; echo "<td>" . $row['phone_number'] . "</td>"; echo "<td>" . $row['fax_number'] . "</td>"; echo "<td>" . $row['email_address'] . "</td>"; echo "<td>" . $row['position_open'] . "</td>"; echo "<td>" . $row['learnmore']; if ( $row['learnmore'] == TRUE ) { echo ""; } else { echo ""; } "</td>"; echo "<td>" . $row['filled']; if ( $row['filled'] == TRUE ) { echo ""; } else { echo ""; }"</td>"; echo "<td>" . $row['closed']; if ( $row['closed'] == TRUE ) { echo ""; } else { echo ""; }"</td>"; echo "<td>" . $row['listing_content'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/177433-mysql-and-php-search/ Share on other sites More sharing options...
resting Posted October 12, 2009 Share Posted October 12, 2009 not sure if i get you right. your 1st problem is more about the presentation of the page? if thats the case you just modify the <td> tags in your script to suit your liking. as for your second problem, you mean you want to delete a row from the database table? in that case use DELETE FROM tablename WHERE condition. you can search google for mysql delete for more information. Link to comment https://forums.phpfreaks.com/topic/177433-mysql-and-php-search/#findComment-935533 Share on other sites More sharing options...
m5638829 Posted October 12, 2009 Author Share Posted October 12, 2009 the first problem is that i want the search results to only display two of the 8 fields. when you click on a "learn more" button, another page is opened with all of the fields displayed. Second problem, I tried with the DELETE FROM tablename WHERE and it just messed it up. i will try again with that. So nevermind that issue. Link to comment https://forums.phpfreaks.com/topic/177433-mysql-and-php-search/#findComment-935539 Share on other sites More sharing options...
m5638829 Posted October 13, 2009 Author Share Posted October 13, 2009 How do you make the DELETE FROM tablename WHERE a link so that I can just click on it? Link to comment https://forums.phpfreaks.com/topic/177433-mysql-and-php-search/#findComment-936218 Share on other sites More sharing options...
resting Posted October 19, 2009 Share Posted October 19, 2009 for your first problem, if you just want to display 2 fields, change your query to this: $result = mysql_query('SELECT * FROM jobs LIMIT 2', $con); for your second problem, a simple way to do it is this: echo "<a href='" . $_SERVER['PHP_SELF'] . "?id=" . $id . "&action=delete'">Delete</a> This link is supposed to be generated dynamically where the $id value correspond to the row you want deleted. if your current page is link.php and the $id is 1, then when parsed it will become: <a href='link.php?id=1&action=delete'>Delete</a> Your link.php will have to contain this code to process the delete if($_GET['action'] === 'delete'){ $query = 'DELETE FROM table WHERE id = $_GET['id']; $result = mysql_query($query); } I'm not sure if its secure if done this way though. Link to comment https://forums.phpfreaks.com/topic/177433-mysql-and-php-search/#findComment-940115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.