PHP - Problem With Edit And Deletes On Differ Tables
Hello, I will try to explain this in as much detail as I can. I am probably making a simple mistake but I have gone through the code multiple times and can't figure it out. I have 3 HTML Site tables, pending, accepted and denied applications. I have accept, deny, and delete buttons on all the tables for each row. I could probably do with out the accept and deny buttons on the last two HTML Site tables, but in the case an admin making a mistake and clicking the wrong button. I don't want the admin to have to delete the app and have the user fill out a new one. User experience and all that. My problem: The last two HTML Site tables, Accept and Denied, the three buttons do not function but in Pending they do. I don't remember assigning those functions to one table and looked thought the code and didn't see any place I did it is only looking for id at the displayed row. Enough of my jabbering. Here is what I am working with.
Here is the code, I have done for the deletes and edits to the application status. //DELETE APPLICATION if(isset($_POST['delete'])) { $to_change = mysqli_real_escape_string($conn, $_POST['to_change']); $sql = "DELETE FROM apps WHERE id = $to_change"; if(mysqli_query($conn, $sql)) { $feedback['delete'] = '<div class="green white-text alert-box">Success the user deleted from list.</div>'; header('Location: admin.php'); } else { $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>'; } } else { $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>'; } //UPDATE APPLICATION STATUS TO ACCEPT if(isset($_POST['accept'])) { $to_change = mysqli_real_escape_string($conn, $_POST['to_change']); //QUERY DB mysqli_query($conn, "UPDATE apps SET app_status='Accepted' WHERE id = $to_change"); $feedback['accept'] = '<div class="green white-text alert-box">Success, the user was accepted.</div>'; header('Location: admin.php'); } else { $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>'; } //UPDATE APPLICATION STATUS TO DENIED if(isset($_POST['denied'])) { $to_change = mysqli_real_escape_string($conn, $_POST['to_change']); //QUERY DB mysqli_query($conn, "UPDATE apps SET app_status='Denied' WHERE id = $to_change"); $feedback['denied'] = '<div class="green white-text alert-box">Success, the user was denied.</div>'; header('Location: admin.php'); } else { $feedback['ui_feedback'] = '<div class="red white-text alert-box">Connection Error</div>'; } I know the $feedback doesn't work I wanted to see it worked and it didn't I will research that later. <!-- NEW APPLICATIONS --> <div id="new_apps" class="container white container-style"> <h4 class="blue-text text-darken-3">New Applications</h4> <div class="table-responsive"> <table class="highlight centered row"> <thead> <tr class=""> <th class="blue-text text-darken-3">ID</th> <th class="blue-text text-darken-3">Name</th> <th class="blue-text text-darken-3">Email</th> <th class="blue-text text-darken-3">Discord</th> <th class="blue-text text-darken-3">Steam Hex ID</th> <th class="blue-text text-darken-3">DOB</th> <th class="blue-text text-darken-3">Department</th> <th class="blue-text text-darken-3">Date Applied</th> <th class="blue-text text-darken-3">Status</th> <th class="blue-text text-darken-3">Actions</th> </tr> <tbody class=""> <?php if($pending): ?> <?php foreach($pending as $pend): ?> <tr> <td><?php echo $pend['id']; ?></td> <td><?php echo $pend['first_name'] . " " . $pend['last_name']; ?></td> <td><?php echo $pend['email']; ?></td> <td><?php echo $pend['discord_name']; ?></td> <td><?php echo $pend['steam_hex']; ?></td> <td><?php echo $pend['dob']; ?></td> <td><?php echo $pend['dept_select']; ?></td> <td><?php echo $pend['created_at']; ?></td> <td><?php echo $pend['app_status']; ?></td> <td> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> <input type="hidden" name="to_change" value="<?php echo $pend['id']; ?>"> <button type="submit" name="accept" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Accept"><i class="material-icons green-text text-darken-3">check_circle</i></button> <button type="submit" name="denied" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Deny"><i class="material-icons yellow-text text-darken-3">not_interested</i></button> <button type="submit" name="delete" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Delete"><i class="material-icons red-text text-darken-3">delete</i></button> </form> </td> </tr> </tbody> <?php endforeach; ?> <?php else: ?> <div class="blue darken-3 white-text table-empty-box">There are no applications</div> <?php endif; ?> </thead> </table> </div> </div> <!-- ACCEPTED APPLICATIONS--> <div id="accepted_apps" class="container white container-style"> <h4 class="blue-text text-darken-3">Accepted Applications</h4> <div class="table-responsive"> <table class="highlight centered row"> <thead> <tr class=""> <th class="blue-text text-darken-3">ID</th> <th class="blue-text text-darken-3">Name</th> <th class="blue-text text-darken-3">Email</th> <th class="blue-text text-darken-3">Discord</th> <th class="blue-text text-darken-3">Steam Hex ID</th> <th class="blue-text text-darken-3">DOB</th> <th class="blue-text text-darken-3">Department</th> <th class="blue-text text-darken-3">Date Applied</th> <th class="blue-text text-darken-3">Status</th> <th class="blue-text text-darken-3">Actions</th> </tr> <tbody class=""> <?php if($accepted): ?> <?php foreach($accepted as $accept): ?> <tr> <td><?php echo $accept['id']; ?></td> <td><?php echo $accept['first_name'] ." " . $accept['last_name']; ?></td> <td><?php echo $accept['email']; ?></td> <td><?php echo $accept['discord_name']; ?></td> <td><?php echo $accept['steam_hex']; ?></td> <td><?php echo $accept['dob']; ?></td> <td><?php echo $accept['dept_select']; ?></td> <td><?php echo $accept['created_at']; ?></td> <td><?php echo $accept['app_status']; ?></td> <td> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> <input type="hidden" name="to_change" value="<?php echo $accept['id']; ?>"> <a type="submit" name="accept" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Accept"><i class="material-icons green-text text-darken-3">check_circle</i></a> <a type="submit" name="denied" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Deny"><i class="material-icons yellow-text text-darken-3">not_interested</i></a> <a type="submit" name="delete" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Delete"><i class="material-icons red-text text-darken-3">delete</i></a> </form> </td> </tr> <?php endforeach; ?> <?php else: ?> <div class="blue darken-3 white-text table-empty-box">There are no applications</div> <?php endif; ?> </tbody> </thead> </table> </div> </div> <!-- deniedED APPLICATIONS --> <div id="denieded_apps" class="container white container-style"> <h4 class="blue-text text-darken-3">Denied Applications</h4> <div class="table-responsive"> <table class="highlight centered row"> <thead> <tr class=""> <th class="blue-text text-darken-3">ID</th> <th class="blue-text text-darken-3">Name</th> <th class="blue-text text-darken-3">Email</th> <th class="blue-text text-darken-3">Discord</th> <th class="blue-text text-darken-3">Steam Hex ID</th> <th class="blue-text text-darken-3">DOB</th> <th class="blue-text text-darken-3">Department</th> <th class="blue-text text-darken-3">Date Applied</th> <th class="blue-text text-darken-3">Status</th> <th class="blue-text text-darken-3">Actions</th> </tr> <tbody class=""> <?php if($denied): ?> <?php foreach($denied as $deny): ?> <tr> <td><?php echo $deny['id']; ?></td> <td><?php echo $deny['first_name'] ." " . $deny['last_name']; ?></td> <td><?php echo $deny['email']; ?></td> <td><?php echo $deny['discord_name']; ?></td> <td><?php echo $deny['steam_hex']; ?></td> <td><?php echo $deny['dob']; ?></td> <td><?php echo $deny['dept_select']; ?></td> <td><?php echo $deny['created_at']; ?></td> <td><?php echo $deny['app_status']; ?></td> <td> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> <input type="hidden" name="to_change" value="<?php echo $deny['id']; ?>"> <a type="submit" name="accept" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Accept"><i class="material-icons green-text text-darken-3">check_circle</i></a> <a type="submit" name="denied" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Deny"><i class="material-icons yellow-text text-darken-3">not_interested</i></a> <a type="submit" name="delete" class="tooltipped btn-floating btn-flat btn-small transparent" data-postion="bottom" data-tooltip="Delete"><i class="material-icons red-text text-darken-3">delete</i></a> </form> </td> </tr> <?php endforeach; ?> <?php else: ?> <div class="blue darken-3 white-text table-empty-box">There are no applications</div> <?php endif; ?> </tbody> </thead> </table> </div> </div>
Any help would be amazing even if you tell me to look at a line lol I am getting back into php after only doing it for a few weeks after switching to firebase, just coming back to what works and not having limits. Thank you for taking the time to read this! Similar Tutorialswhen the blow code is ran it produces this warning error Quote Warning: filemtime() [function.filemtime]: stat failed for 048_Baby_Colors.png in /home/public_html/.com/kill.php on line 23 The code deletes all the files in the directory no matter how many hours or seconds ago they was last modified. could someone help me figure out why? <?php $dir = '/home/br/public_html/l.com/dfile'; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file[0] == '.' || is_dir("$dir/$file")) { continue; } if ((time() - filemtime($file)) > ($days * 604800)) { unlink("$dir/$file"); } } closedir($handle); } ?> I found this bug when creating my topic he
http://forums.phpfre...ted-rectangles/
I spent 10 minutes writing up my issue after I copy and pasted my code inside the [code=auto:0] brackets. Then, what do you know? I submitted my post with all my writing below my [code=auto:0] brackets and BOOM it was all gone. Only my code was showing. That's what issued Requinex to reply like that, it's a nasty forum bug.
Here is a video I made to help explain and re-create the issue. Hopefully you guys fix it, thanks!
Is this true, i have cookies on my site till i send a form which fires off two emails. the cookies are not only deleted, but i can reset the cookie to the proper values unless i delete all my cookies!! any ideas? The title says it all,..well as all u can see, there are many methods to accomplish this done but not before undergoing through a heavy tasking process. For instance, 1. Open the file 2. Reads the content of the file into array. 3. Find out the desire line of text that we want to replace. 4. Make that line of text as variable and assigns with the new data(that we want to replace) as its values. 5.open another file. 6.Write the whole contents to the file opened in 5. 7. Put the contents back to the file of original. Can anyone contributes a better way to get this done? Like replace/delete a specific line without affecting other characters or anything therein? Thanx. P.S reading and using str_replace to make the alteration always ends up in giving some kind of result beyond desired after the first round of code execution. My validation Code: [Select] <?php if(!isset($_POST['submit'])) { if(!isset($_GET["id"])) { me_redirect_to("staff.php"); } } ?> is redirecting me even if my $_POST['submit'] is set here's the full code Code: [Select] <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php require("includes/header.php"); ?> <?php require("includes/navbar.php"); ?> <?php require("staff_sidebar.php"); ?> <?php if(!isset($_POST['submit'])) { if(!isset($_GET["id"])) { me_redirect_to("staff.php"); } } ?> <?php if(!isset($_POST['submit'])) { if(!is_numeric($_GET["id"])) { me_redirect_to("staff.php"); } } ?> <?php if(isset($_GET['id'])); { $i = 0; $edit_proj_id = $_GET['id']; $edit_query = "Select proj_name, content from rec_projects where proj_id = {$edit_proj_id}"; $edit_result = mysql_query($edit_query, $connection); $num = mysql_num_rows($edit_result); if($num != 1) { me_redirect_to("staff.php"); } $edit_proj_name = mysql_result($edit_result,$i,"proj_name"); $edit_content = mysql_result($edit_result,$i,"content"); } ?> <div id="content"> <h1>Edit Subject</h1><br> <?php if(isset($_POST['submit'])) { $proj_name = me_mysql_prep(trim($_POST['proj_name'])); $proj_content = me_mysql_prep($_POST['proj_content']); if(empty($_POST['proj_name'])) { $empty_name = array('Project Name Cannot Be Empty'); } if(empty($_POST['proj_content'])) { $empty_content = array('Content Cannot Be Empty'); } if(isset($empty_name) && isset($empty_content)) { $error_merge = array_merge($empty_name, $empty_content); } else if(isset($empty_name)) { $error_merge = array_merge($empty_name); } else if(isset($empty_content)) { $error_merge = array_merge($empty_content); } else { $error_merge = array(); } if(!empty($error_merge)) { foreach($error_merge as $error) { echo "<span class=\"error_validation\">*". $error . "<br></span>"; } } else { $query = "UPDATE rec_projects SET proj_name='{$proj_name}', content='{$proj_content}' where proj_id = {$edit_proj_id}"; if($result = mysql_query($query,$connection)) { me_redirect_to("edited_project.php?edited=1"); } else { echo "Can\'t edit the project: ". mysql_error() . ""; } } echo "<br><br>"; } ?> <table> <tr><td> </td></tr> </table> <table> <form action="edit_project.php" method="post" name="add_subject"> <tr> <td>Project Name:</td> <td><input type="text" size="50" name="proj_name" value="<?php echo $edit_proj_name; ?>"></td> </tr> <tr> <td>Content:</td> <td><textarea cols="70" rows="20" name="proj_content"><?php echo $edit_content; ?></textarea></td> </tr> <tr> <td></td> <td><input type="submit" value="Edit Project" name="submit" id="submit" size="30"></td> </tr> </form> </table> </div> <?php require("includes/footer.php"); ?> It's suppose to be executing the mysql edit query but it's bypassing my validation. I wonder what the problem is.. hello all, i am trying to edit a mysql table from the browser using these codes: edit.php: include"db.inc.php";//database connection $order = "SELECT * FROM prices"; $result = mysql_query($order); while ($row=mysql_fetch_array($result)){ echo ("<tr><td>$row[id_number]</td>"); echo ("<td>$row[product]</td>"); echo ("<td>$row[price]</td>"); echo ("<td><a href=\"edit_form.php?id=$row[id_number]\">Edit</a></td></tr>"); } edit_form.php <table> <? include "db.inc.php";//database connection $order = "SELECT * FROM prices where id_number='$id'"; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> <form method="post" action="edit_data.php"> <input type="hidden" name="id" value="<? echo "$row[id_number]"?>"> <tr> <td>Product</td> <td> <input type="text" name="product" size="20" value="<? echo "$row[product]"?>"> </td> </tr> <tr> <td>Price</td> <td> <input type="text" name="price" size="40" value="<? echo "$row[price]"?>"> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit value" value="Edit"> </td> </tr> </form> </table> edit_data.php include "db.inc.php"; $order = "UPDATE prices SET product='$_POST[product]', price='$_POST[price]' WHERE id_number='$id'"; mysql_query($order); header("location:edit.php"); the table: CREATE TABLE IF NOT EXISTS `prices` ( `id_number` int(3) NOT NULL, `product` varchar(30) DEFAULT NULL, `price` int(6) DEFAULT NULL, PRIMARY KEY (`id_number`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; the data is displayed correctly but i can't change the data... Hi There I am trying to create a page that edit mysql database from a php page. I can get the edit page to show the orginal information but it wont update the data in the mysql database. I am sure I have entered everything right. If anyone could help with this I would greatly appreciated <?php include("dbconnect.php"); if(isset($_POST['submit'])) { // Set global variables to easier names // and prevent sql injection and apostrophe to break the db. $ProductName = mysql_escape_string($_POST['ProductName']); $ProductText = mysql_escape_string($_POST['ProductText']); $ProductImage = mysql_escape_string($_POST['ProductImage']); $ProductPrice = mysql_escape_string($_POST['ProductPrice']); $result = mysql_query("UPDATE Product SET ProductName='$ProductName', ProductText='$ProductText', ProductImage='$ProductImage', ProductPrice='$ProductPrice' WHERE ID='$ID' ",$dbconnect); echo "<b>Thank you! Product UPDATED Successfully!<br>You'll be redirected to View Page after (2) Seconds"; echo "<meta http-equiv=Refresh content=2;url=view.php>"; echo "$ProductName <br> $ProductText <br> $ProductImage <br> $ProductPrice"; } elseif(isset($_GET['ID'])) { $result = mysql_query("SELECT * FROM Product WHERE ID='$_GET[ID]' ",$dbconnect); while($myrow = mysql_fetch_assoc($result)) { $ProductName = $myrow["ProductName"]; $ProductText= $myrow["ProductText"]; $ProductImage = $myrow["ProductImage"]; $ProductPrice = $myrow["ProductPrice"]; ?> <br> <h3>::Edit Product</h3> <form method="post" action="<?php echo $PHP_SELF ?>"> <input type="hidden" name="ID" value="<? echo $myrow['ID']?>"> Product Name: <input name="ProductName" size="40" maxlength="255" value="<? echo $ProductName; ?>"><br> Product Text: <textarea name="ProductText" rows="7" cols="30"><? echo $ProductText; ?></textarea><br> Product Image: <textarea name="ProductImage" rows="7" cols="30"><? echo $ProductImage; ?></textarea><br> Product Price: <textarea name="ProductPrice" rows="7" cols="30"><? echo $ProductPrice; ?></textarea><br> <input type="submit" name="submit" value="Update Product"> </form> <? }//end of while loop }//end else ?> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=322008.0 Hi, I got a problem with two tables. There is a one with users, and the other is with logs of the users. USERS table - ID - name LOGS table - ID - users_ID - log_datetime I want to list this tables like this Name 1 - log_datetime - log_datetime - log_datetime... Name 2 - log_datetime - log_datetime - log_datetime... Name 3 - log_datetime - log_datetime - log_datetime... So, every names just one time, and below every log belong to that name... Thanks.. T I'm trying to combine 3 tables (attacks, spells, skills) where it brings in all the information from attacks and spells into the table skills. The common row between all 3 is "name". Here is what I have so far. $query = "SELECT * FROM `skills`,`attacks`,`spells` WHERE (`attacks.name`=`skills.name` OR `spells.name`=`skills.name`) AND `user_id`='".$_SESSION['userid']."'"; Thanks! Hi, My name is stefan and I've been trying to develop a php/mysql based CRM for private use. I've stumbled upon a problem a few days ago and I just can't figure it out, so if you could help me, I'd really appreciate it. The problem is the following: I have 1 database which contains 5 tables. Each table has info in it but the primary key always is 'ID' 4 Tables are named; Zendingen | Klanten | Manden | Bestemmeling The last table, named 'Combination' has the unique ID of each of those 4 in it. The example will be given below. What I want to do now is create a page that shows all stored rows in 'Combination'-table, but gets the proper client_name or product_info out of the corresponding table. I have searched for it myself but I have no clue where to begin and how to define my searches so they all stranded. This is the piece of code. Code: (php) [Select] $Shipm1 = mysql_query("SELECT * FROM Shipments where Zending_ID = 9") or die(mysql_error()); while($row = mysql_fetch_assoc($Shipm1)) { echo "<br />"; echo $row["ID"]; echo "<br />"; echo $row["Zending_ID"]; echo "<br />"; echo $row["Klant_ID"]; echo "<br />"; echo $row["Mand_ID"]; echo "<br />"; echo $row["Bestemmeling_ID"]; echo "<br />"; }This code returns: Quote 3 ---- the ID of the 'combination' table and thus primary key 9 ---- Zending_ID 47 --- Klant_ID 17 --- Mand_ID 2 ---- Bestemmeling_ID 4 This is another row from the combinations table, 9 notice that it only returns the Zending_ID = 9. 49 21 4 Now this gives me the info I want, but it doesn't displays them how I need it to. I want it to search up each ID in the proper table and return me the product name, client name etc... Anyone who can help or point me in the right direction? Kind regards Stefan Hello Im trying to achieve the following output (see the below table. Then on a new row have the next 4 pieces of data that is pulled from the database. So i want the table to automatically have a new row after every 4 cells e.g. 1st piece of data 2nd piece 3rd piece 4th piece 5th piece of data 6th piece 7th piece 8th piece etc etc, until there is no more results within the database to pull back, i guess its a bit like pagination but rather rowination Any one point me in the right direction on what i need to do Hi, I'm trying to insert data into two different tables using, but am getting an error I can't figure out. If I move the $mysqli->commit(); into the foreach loop, I get at least one returned row before the rest fail. The error current error message is Array ( [0] => Error: Couldn't insert into english! ). Any idea what is causing this?
<?php $file_array = file('../grammar/conjunctions.txt'); $csv = array_map('str_getcsv', $file_array); // DB $mysqli = new mysqli('localhost', 'root', '******', 'angos'); $mysqli->autocommit(false); $error = array(); foreach($csv as $value) { $angos_query = $mysqli->query("INSERT INTO angos (angos, grammar) VALUES ('$value[0]', 'con')"); $id = $mysqli->insert_id; // grab the currant angos table id if($angos_query == false) { array_push($error, "Error: Couldn't insert into angos!"); } $english_query = $mysqli->query("INSERT INTO english (angos_id, english) VALUES ('$id', '$value[1]')"); if($english_query == false) { array_push($error, "Error: Couldn't insert into english!"); } if(!empty($error)) { $mysqli->rollback(); } } $mysqli->commit(); print_r($error); // print_r($csv); ?>More info SQL: CREATE TABLE angos ( id int unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, angos varchar(255) not null, grammar varchar(3) not null, updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, CONSTRAINT unique_input UNIQUE (angos) ) engine=InnoDB; CREATE TABLE english ( id int unsigned not null primary key, angos_id int unsigned, english varchar(255), grammar_note varchar(500), CONSTRAINT fk_angos_source FOREIGN KEY (angos_id) REFERENCES angos(id) ON DELETE CASCADE ON UPDATE CASCADE ) engine=InnoDB; hello all, i want to display each row from mysql table in a different page using this code: Code: [Select] <? require_once('config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die("can't connect: " . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("can't select database"); } mysql_query("SET NAMES 'hebrew'"); //mysql_set_charset('utf8',$link); if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = $page-1; $qry='SELECT * FROM ordering limit 0, 1'; $result = mysql_query($qry); while($row = mysql_fetch_array($result)){ echo "<div dir='rtl' charset='utf8'><h2>"," hover cam: ",$row['hover_camera'], "<br> stills: ",$row['stills'], "<br> video_photographers: ",$row['video_photographers'], "<br> increase: ",$row['increase'], "<br> video_edit: ",$row['video_edit'], "<br> digital_album: ",$row['digital_album'], "<br> photo_album: ",$row['photo_album'], "<br> small_digital_album: ",$row['small_digital_album'], "<br> video_clip: ",$row['video_clip'], "<br> magnets: ",$row['magnets'], "<br> comments: ",$row['comments'], "<br> date: ",$row['date'], "<br><br></h2></div>"; } $sql = "SELECT COUNT(userid) FROM ordering"; $result = mysql_query($sql,$link); $row2 = mysql_fetch_row($result); $total_records = $row2[0]; $total_pages = $total_records ; for ($i=1; $i<=$total_pages; $i++) { echo "<a href='table.php?page=".$i."'>".$i."</a> "; }; ?> this is the table: Code: [Select] CREATE TABLE IF NOT EXISTS `ordering` ( `userid` int(11) unsigned NOT NULL AUTO_INCREMENT, `hover_camera` varchar(10) DEFAULT NULL, `stills` int(5) NOT NULL, `video_photographers` int(5) NOT NULL, `increase` int(5) NOT NULL, `video_edit` varchar(10) NOT NULL, `digital_album` varchar(10) DEFAULT NULL, `photo_album` varchar(10) DEFAULT NULL, `small_digital_album` varchar(20) DEFAULT NULL, `video_clip` varchar(10) DEFAULT NULL, `magnets` int(10) NOT NULL, `comments` text NOT NULL, `date` date NOT NULL, PRIMARY KEY (`userid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; the problem is that only the first row is displayed no matter which page i choose and i want each page to display the row assigned to it (page 15 = row 15 etc...) any suggestions? hello i have a mysql table and i want to display each row in a different page with an added condition, the code: Code: [Select] if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = $page-1; $qry="SELECT * FROM ordering WHERE userid='$page' AND email='$email' LIMIT 0,1"; $result = mysql_query($qry); while($row = mysql_fetch_array($result)){ echo "<div dir='rtl' charset='utf8'><h2>"," hover cam: ",$row['hover_camera'], "<br> stills: ",$row['stills'], "<br> video_photographers: ",$row['video_photographers'], "<br> increase: ",$row['increase'], "<br> video_edit: ",$row['video_edit'], "<br> digital_album: ",$row['digital_album'], "<br> photo_album: ",$row['photo_album'], "<br> small_digital_album: ",$row['small_digital_album'], "<br> video_clip: ",$row['video_clip'], "<br> magnets: ",$row['magnets'], "<br> comments: ",$row['comments'], "<br> date: ",$row['date'], "<br><br></h2></div>"; } $sql = "SELECT COUNT(userid) FROM ordering"; $result = mysql_query($sql,$link); $row2 = mysql_fetch_row($result); $total_records = $row2[0]; $total_pages = $total_records ; for ($i=1; $i<=$total_pages; $i++) { echo "<a href='myorders.php?page=".$i."'>".$i."</a> "; }; the table is as so: Code: [Select] CREATE TABLE IF NOT EXISTS `ordering` ( `userid` int(11) unsigned NOT NULL AUTO_INCREMENT, `hover_camera` varchar(10) DEFAULT NULL, `stills` int(5) NOT NULL, `video_photographers` int(5) NOT NULL, `increase` int(5) NOT NULL, `video_edit` varchar(10) NOT NULL, `digital_album` varchar(10) DEFAULT NULL, `photo_album` varchar(10) DEFAULT NULL, `small_digital_album` varchar(20) DEFAULT NULL, `video_clip` varchar(10) DEFAULT NULL, `magnets` int(10) NOT NULL, `comments` text NOT NULL, `date` date NOT NULL, `fname` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, PRIMARY KEY (`userid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; now to the problem: this code displays all the userid as page numbers however, the email condition is good only for part of the rows it's a little hard to explain, i'll try an example: suppose the email '1@1.com' is at rows 22,25 and 30 my code displays 30 page numbers and page 22 is user 22, page 25 is user 25 etc. what i want is to display only the page numbers of the pages with the conditional email, and if possible to display them as 1,2,3 instead of 22,25,30 Im doing a search system and Im having some problems.
I need to search in two tables (news and pages), I already had sucess doing my search system for just one table, but for two tables its not easy to do.
I already use a select statment with two tables using UNION because I want to show number of search results, that is number of returned rows of my first sql statment.
But now I need to do a select statment that allows me to acess all fields of my news table and all fields of my pages table.
I need to acess in my news table this fields: id, title, content, link, date, nViews
I need to acess in my pages table this fields: id, title, content, link
Im trying to do this also with UNION, but in this case Im not having any row returning.
Do you see what I have wrong in my code?
<?php //first I get my $search keyword $search = $url[1]; $pdo = connecting(); //then I want to show number of returned rows for keyword searched $readALL = $pdo->prepare("SELECT title,content FROM news WHERE title LIKE ? OR content LIKE ? UNION SELECT title,content FROM pages WHERE title LIKE ? OR content like ?"); $readALL->bindValue(1,"%$search%", PDO::PARAM_STR); $readALL->bindValue(2,"%$search%", PDO::PARAM_STR); $readALL->bindValue(3,"%$search%", PDO::PARAM_STR); $readALL->bindValue(4,"%$search%", PDO::PARAM_STR); $readALL->execute(); //I show number of returned rows echo '<p>Your search keyword returned <strong>'.$readALL->rowCount().'</strong> results!</p>'; //If dont return any rows I show a error message if($readALL->rowCount() <=0){ echo 'Sorry but we didnt found any result for your keyword search.'; } else{ //If return rows I want to show, if it is a page result I want to show title and link that I have in my page table //if it is a news result I want to show title and link that I have in my news table and also date of news echo '<ul class="searchlist">'; $readALL2 = $pdo->prepare("SELECT * FROM news WHERE status = ? AND title LIKE ? OR content LIKE ? LIMIT 0,4 UNION SELECT * FROM pages where title LIKE ? OR content LIKE ? LIMIT 0,4"); $readALL2->bindValue(1, '1'); $readALL2->bindValue(2, "%$search%", PDO::PARAM_STR); $readALL2->bindValue(3, "%$search%", PDO::PARAM_STR); $readALL2->bindValue(4, "%$search%", PDO::PARAM_STR); $readALL2->execute(); while ($result = $readALL2->fetch(PDO::FETCH_ASSOC)){ echo '<li>'; echo '<img src="'.BASE.'/uploads/news/'.$result['thumb'].'"/>'; echo '<a href="'.BASE.'/news/'.$result['id_news'].'">'.$result['title'].'</a>'; //if it is a news result I also want to show date on my list //echo '<span id="date">'.$result['date'].'</span>'; echo '</li>'; } echo ' </ul>'; //but how can I do my select statement to have access to my news table fields and my page table fields?? } ?> This portion is kind of stumping me. Basically, I have a two tables in this DB: users and users_access_level (Separated for DB normalization) users: id / username / password / realname / access_level users_access_level: access_level / access_name What I'm trying to do, is echo the data onto an HTML table that displays users.username in one table data and then uses the users.access_level to find users_access_level.access_name and echo into the following table data, I would prefer not to use multiple queries if possible or nested queries. Example row for users: 1234 / tmac / password / tmac / 99 Example row for users_access_level: 99 / Admin Using the examples above, I would want the output to appear as such: Username: Access Name: Tmac Admin I am not 100% sure where to start with this, but I pick up quickly, I just need a nudge in the right direction. The code I attempted to create just shows my lack of knowledge of joining tables, but I'll post it if you want to see that I did at least make an effort to code this myself. Thanks for reading! I am trying to write some data from multiple SQL tables to a page. In the first table is a list of places. I then have more tables that are named after the different places. For example, say my first place in the list is called Place1. I have a table named Place1 with data that corresponds to place1. The data contained in the table named Place1 is a list of things to do in this place. It has 21 columns and each one is something to do in the morning, afternoon, and at night for each day of the week in the place Place1. What I am trying to do is display a sort of weekly calendar as a table on a webpage that lists all of the places in one column and then lists seven days of the week as 7 more columns. Then in each data cell I would want to list the things to do in the morning, afternoon and at night for the certain day of the week and for the place. The problem is that I am creating a CMS to allow other users with no coding knowledge to update events for other places, so I have to display data that could have been altered. The only solution I know of is to do a while loop that gets all of the place names and while there are still place names, write the place names to the page and set a variable equal to the place name. Inside the while loop I would create another while loop that each time the first while loop is executed uses the variable set in the first while loop to know which table to reference and then make a call to that table pulling out the 21 columns and writing them to the page. Each time the outer while loop executes, it would (hopefully) write the place name, and then set the variable as the current place name so that the inner while loop uses the variable to write the rest of the information about that place. I don't know if that would even work and if it did, I know it cannot be the best way to do this. I am pretty stuck here and don't really have a good solution so if anyone proposes a solution that is radically different to anything I have done, I am open to everything. Thank you! hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks I'm using php edit function to edit an php file online. I think the portion that writing the file is below. My issue is that wherever there's a quote ("), it's automatically adding a slash (\). For example, if I had class="abc", it changes to class=\"abc\". How do I fix this? Code: [Select] <?php $file = $_GET['f']; $script = $_POST['script']; if($file&&$script) { $fp=fopen($file, "w"); fwrite($fp,$script); fclose($fp); } ?> |