PHP - Problem Combining Tables
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! Similar TutorialsI am trying to combine two tables into one query. This is what I tried but it wont work: Code: [Select] <?php include ('includes/db.php'); include ('includes/functions.php'); include ('includes/global.php'); session_start(); echo '<table width="100%">'; $statsql="SELECT * from `wall`,`feed` WHERE ORDER BY `id` DESC LIMIT 0,10"; $statres=mysql_query($statsql) or die(mysql_error()); while($statrow=mysql_fetch_array($statres)){ $vmessage=clean_up($statrow[message]); $date=clean_up($statrow[date]); $time=clean_up($statrow[time]); $by=clean_up($statrow[by]); $type=clean_up($statrow[type]); if($vmessage){ $usersql="SELECT * from `users` WHERE `id`='$by'"; $useres=mysql_query($usersql) or die(mysql_error()); while($row=mysql_fetch_array($useres)){ $avatar=clean_up($row[avatar]); $first=clean_up($row[first]); echo "<tr class='content'><td valign='top'> <img src='pic.php?w=50&h=50&constrain=1&img=photos/$avatar' /><br>$first"; } echo "</td><td valign='top'> $vmessage</td></tr>"; }else{ echo "$type<br>"; } } echo "</table>"; ?> Could someone help me out? Thanks! 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 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, 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 Hi , im completely new to php and mysql. I have 2 websites running on the same server and im just wondering if there is a way that when someone logs into one of the websites that it will automatically log them in the other website as well so that they don't have to log in again. Maybe if you can point to some good beginner reading material or something that would be great.
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? 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, 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! Hi there everyone! I've got a problem combining two queries. The situation is this. I've got a list of links and I want to allow the user to get a result list of all, only unread, all in a particular category and then only unread in a particular category. My query for all: /* No filtering and no unread */ $q_urls = "SELECT * FROM shortenified_urls WHERE is_social = '1' AND active = '1' ORDER BY date_added DESC"; My query for in a particular category: /* All links in a particular category */ $q_urls = " SELECT * FROM shortenified_urls WHERE shortenified_urls.primary_cat = $vu_cat_view OR EXISTS ( SELECT link_id FROM linkcats WHERE link_id = shortenified_urls.id AND cat_id = $vu_cat_view ) AND shortenified_urls.is_social = '1' AND shortenified_urls.active = '1' ORDER BY date_added DESC" ;My query for Unread in all cats: /* Unread only for all categories */ $q_urls = "SELECT * FROM shortenified_urls WHERE shortenified_urls.date_added > $vu_mark_as_read AND NOT EXISTS ( SELECT lid FROM linkviews WHERE lid = shortenified_urls.id AND uid = $viewing_user_id ) AND shortenified_urls.is_social = '1' AND shortenified_urls.active = '1' ORDER BY date_added DESC" ; These seem to be working well. It's the next one that isn't working for me. I tried to combine the "All in a particular category" and "Unread in all categories" using the two above as starting points. The result, however, seems to be that I'm getting all in a particular category. It seems to be ignoring the unread status. /* Unread links in a particular category */ $q_urls = " SELECT * FROM shortenified_urls WHERE shortenified_urls.primary_cat = $vu_cat_view AND shortenified_urls.date_added > $vu_mark_as_read OR EXISTS ( SELECT link_id FROM linkcats WHERE link_id = shortenified_urls.id AND cat_id = $vu_cat_view ) AND NOT EXISTS ( SELECT lid FROM linkviews WHERE lid = shortenified_urls.id AND uid = $viewing_user_id ) AND shortenified_urls.is_social = '1' AND shortenified_urls.active = '1' ORDER BY date_added DESC" ;I'm not smart enough to know why it's not working, but it seems to me like I need to somehow bracket the first two parts containing the category retrieval to make this work right. The only problem is I don't know how to do that. Any help on how to get this to work would be greatly appreciated! i'm having trouble in combining the 2 preg_replace into 1. basically i have a string witch strange chars, first i remove all except alphanumeric chars and the remaining string has 1 or 2 spaces and i replace them with dash. Code: [Select] strtolower(preg_replace('/\s+/', '-', preg_replace("/[^0-9a-zA-Z]/i", ' ',$a['item']))); Hello all, I have a simple form which ends in header( "Location: thankyou.php" ); What I have done on the site so far is to use Ajax to load content into a specific Div which uses the following code <a href="javascript:ajaxpage('home.php', 'content-index');"></a> Is there a way to effectively combine the two together to load the thankyou page (upon pressing submit) into the content-index div? Thank you in advance Hi there, I'm a beginner at php and mysql. I know a few basics, but i'm stuck. I'm trying to make something for my wifes company that will be as simple as i can make it. The files i have: login/register script (register.php / regcheck.php) member / profile script and a image upload script. (upload.php: which is now in register.php and process.php) What i want to do is: at register i've added a file upload form, but the reg.php points to regcheck.php and the upload.php points to process.php I want to combine those 2 files: regcheck.php and process.php to one file. Now i've been breakin my head over this for 2 day's and i cant find a solution and i'm not that experienced. what i've done so far is the following, but it does'nt fill my database: databas.sql: CREATE TABLE `klanten` ( `id` int(4) unsigned NOT NULL auto_increment, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, `level` int(4) default '1', `filename` varchar(255) not null, `mime_type` varchar(255) not null, `file_size` int not null, `file_data` mediumblob not null, primary key (image_id), index (filename) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; <?php ob_start(); function assertValidUpload($code) { if ($code == UPLOAD_ERR_OK) { return; } switch ($code) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $msg = 'Image is too large'; break; case UPLOAD_ERR_PARTIAL: $msg = 'Image was only partially uploaded'; break; case UPLOAD_ERR_NO_FILE: $msg = 'No image was uploaded'; break; case UPLOAD_ERR_NO_TMP_DIR: $msg = 'Upload folder not found'; break; case UPLOAD_ERR_CANT_WRITE: $msg = 'Unable to write uploaded file'; break; case UPLOAD_ERR_EXTENSION: $msg = 'Upload failed due to extension'; break; default: $msg = 'Unknown error'; } throw new Exception($msg); } $errors = array(); try { if (!array_key_exists('image', $_FILES)) { throw new Exception('Image not found in uploaded data'); } $image = $_FILES['image']; // ensure the file was successfully uploaded assertValidUpload($image['error']); if (!is_uploaded_file($image['tmp_name'])) { throw new Exception('File is not an uploaded file'); } $info = getImageSize($image['tmp_name']); if (!$info) { throw new Exception('File is not an image'); } } catch (Exception $ex) { $errors[] = $ex->getMessage(); } if( isset( $_POST['user'] ) && isset( $_POST['pass'] ) ) { if( strlen( $_POST['user'] ) < 4 ) { echo "Username Must Be More Than 4 Characters."; } elseif( strlen( $_POST['pass'] ) < 4 ) { echo "Passwrod Must Be More Than 4 Characters."; } elseif( $_POST['pass'] == $_POST['user'] ) { echo"Username And Password Can Not Be The Same."; } else { include( 'database.php' ); $username = mysql_real_escape_string( $_POST['user'] ); $password = md5( $_POST['pass'] ); $filename = mysql_real_escape_string($image['name']); $mime_type = mysql_real_escape_string($info['mime']); $file_size = $image['size']; $file_data = mysql_real_escape_string(file_get_contents($image['tmp_name']) $sqlCheckForDuplicate = "SELECT username FROM klanten WHERE username = '". $username ."'"; if (count($errors) == 0) { // no errors, so insert the image if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO klanten( username, password, filename, mime_type, file_size, file_data ) VALUES( '". $username ."', '". $password ."', '". $filename ."', '". $mime_type ."', '". $file_size ."', '". $file_data ."', )"; if( !mysql_query( $sqlRegUser ) ) { echo "You Could Not Register Because Of An Unexpected Error."; } else { echo "You Are Registered And Can Now Login"; $formUsername = $username; header('Location: view.php?id=' . $id); } } else { echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One."; $formUsername = $username; } } } else { echo "You Could Not Be Registered Because Of Missing Data."; } ob_end_clean(); ?> <html> <head> <title>Error</title> </head> <body> <div> <p> The following errors occurred: </p> <ul> <?php foreach ($errors as $error) { ?> <li> <?php echo htmlSpecialChars($error) ?> </li> <?php } ?> </ul> <p> <a href="upload.php">Try again</a> </p> </div> </body> </html> I guess i've mixed up things pretty badly right? Hi, I'm so close to having this work how I want but one last thing! I have a form with a drop down box with the numbers 1 - 60 in. I have created a view that returns any numbers people have submitted with their login names, e.g. 1 - Laurie 4 - Craig What I need to happen is it to list all the empty numbers too, so like this: 1 - Laurie 2 - 3 - 4 - Craig 5 - etc This code removes numbers that have already been selected from the drop down box (so after Laurie and Craig had chosen 1 & 4 the drop down box would now show 2, 3, 5, 6 etc) https://pastebin.com/dAps0kqJ and this code subtotals the rider numbers (I was just trying to get a custom view to work so am pleased this returns something) https://pastebin.com/A7MwSQ2S Using the first code how do I edit the second code so that it displays every number whether a user has chosen it or not? Thank you!!
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310184.0 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 Hey, I have the following two arrays, of which I want to use bits of each from to get another array. Array 1: Array ( [0] => Array ( [shop_id] => 1 [shop_name] => Aldi [shop_district] => 6 ) [1] => Array ( [shop_id] => 2 [shop_name] => Greggs [shop_district] => 6 ) [2] => Array ( [shop_id] => 3 [shop_name] => Tesco [shop_district] => 6 ) [3] => Array ( [shop_id] => 4 [shop_name] => Morrisons [shop_district] => 6 ) [4] => Array ( [shop_id] => 5 [shop_name] => Ryman [shop_district] => 6 ) [5] => Array ( [shop_id] => 6 [shop_name] => Boots [shop_district] => 6 ) [6] => Array ( [shop_id] => 7 [shop_name] => Superdrug [shop_district] => 6 ) [7] => Array ( [shop_id] => 8 [shop_name] => City [shop_district] => 2 ) [8] => Array ( [shop_id] => 9 [shop_name] => Lizard [shop_district] => 6 ) [9] => Array ( [shop_id] => 10 [shop_name] => Asda [shop_district] => 8 ) [10] => Array ( [shop_id] => 11 [shop_name] => Tesco [shop_district] => 2 ) [11] => Array ( [shop_id] => 12 [shop_name] => Tesco [shop_district] => 8 ) ) Array ( [0] => Array ( [shop_id] => 1 [shop_name] => Aldi [shop_district] => 6 ) [1] => Array ( [shop_id] => 2 [shop_name] => Greggs [shop_district] => 6 ) [2] => Array ( [shop_id] => 3 [shop_name] => Tesco [shop_district] => 6 ) [3] => Array ( [shop_id] => 4 [shop_name] => Morrisons [shop_district] => 6 ) [4] => Array ( [shop_id] => 5 [shop_name] => Ryman [shop_district] => 6 ) [5] => Array ( [shop_id] => 6 [shop_name] => Boots [shop_district] => 6 ) [6] => Array ( [shop_id] => 7 [shop_name] => Superdrug [shop_district] => 6 ) [7] => Array ( [shop_id] => 8 [shop_name] => City [shop_district] => 2 ) [8] => Array ( [shop_id] => 9 [shop_name] => Lizard [shop_district] => 6 ) [9] => Array ( [shop_id] => 10 [shop_name] => Asda [shop_district] => 8 ) [10] => Array ( [shop_id] => 11 [shop_name] => Tesco [shop_district] => 2 ) [11] => Array ( [shop_id] => 12 [shop_name] => Tesco [shop_district] => 8 ) ) Array 2: Array ( [0] => Array ( [SUM(item_price)] => 31.23 [item_shop] => 1 ) [1] => Array ( [SUM(item_price)] => 1.65 [item_shop] => 2 ) [2] => Array ( [SUM(item_price)] => 41.23 [item_shop] => 3 ) [3] => Array ( [SUM(item_price)] => 7.98 [item_shop] => 4 ) [4] => Array ( [SUM(item_price)] => 4.49 [item_shop] => 7 ) ) I'd love if anyone could tell me how I can generate an array that will combine bits of these two arrays, so that using the first array I can get a shop_name and shop_district for each item_shop (aka shop_id). Then I want to get an array with entries that look something like this: [0] => Array ( [SUM(item_price)] => 31.23 [shop_name] => Aldi [shop_district] => 6 ) Thanks so much for your help, it means a lot to me. Hello all, I have an online script that counts the online registered users, guests and bots. The script displays the users names that are online, and the bots names that are online. Since a user can only be logged in at one time on one machine, I have no issues with duplicates here. My issue is that bots appear depending how many are online, it'll say for example: Users Online Matt, Frank, Taylor, Google[bot], Google[bot], Google[bot]. I want to combine the bots, so it'll say: Matt, Frank, Taylor, Google[bot][3]. I've tried doing this with if statements alone, but it seems maybe I'll need a php function to do this with, how would I go about doing this? Thanks in advance, Matt. In a simple text field in a form.... the browser automatically offers a list, when either when you click in or start typing in the field, of previous entries. My question is: Does anyone know how to control this? Is it possible to give a list of values to the browser, sort of like a ajax search, but all sent before. For example; in one field the user must enter a name, i want the text box to offer name possibilities even before the user has entered any on the form previously... sort of combining the <text> with a <select> menu... with all the name possibilities coming from a mysql table I need some help please. I have a project that has a login script that is required before moving to a shopping cart and each use a session. I have a login script that i know works separate of the cart and vice versa. The problem is that when i access the cart i get the session errors and it quits working. So i need help with getting the 2 combined so i can run the cart script while a user is logged in. Here is the code i have. This is the login script session: <? ob_start(); session_start();include_once"config.php"; if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ header("Location: login.php"); }else{ $user_data = "".$_SESSION['username'].""; $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `members` WHERE `username`='".$user_data."'")); } ?> This is the script session for the shopping cart: <?php require_once 'library/config.php'; require_once 'library/category-functions.php'; require_once 'library/product-functions.php'; require_once 'library/cart-functions.php'; $_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI']; $catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0; $pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0; require_once 'include/header.php'; ?> and any help is very much appreciated. |