PHP - Two Tables Problem
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 Similar TutorialsI'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! 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, 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! 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 hi everyone, Whats the best way to put my displayed php into my table? I already have gotten to the point where it is displayed, but it looks basic, so i want it to look like the table below it.... i just havent quite figured out how to "space" the data out so it looks better? Is it just a case of printing out what i want where in the table? or is it something more complex? http://www.removalspace.com/indextwo.php Hi everyone... I have a thumbnail page that is putting out tables that are skewed and I am not able to use CSS properly because of that. Is there anyways I can change the PHP output? This is my code... I think the highlighted area is responsible for my tables? But it is mismatching the <tr> and <td> tags.... I really want it to show a structured table.. like <table> <tr> <td> </td> </tr> </table> // Thumbnail Listing else if( $cid && empty( $pid ) ) { $number_of_thumbs_in_row = 4; // If current page number, use it // if not, set one! if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } // Define the number of results per page $max_results = 400; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); $result = mysql_query(" SELECT photo_id , photo_caption , photo_filename , photo_category FROM gallery_photos WHERE photo_category='".addslashes($cid)."' LIMIT $from, $max_results "); $nr = mysql_num_rows( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Photos found</td></tr>\n"; } else { while( $row = mysql_fetch_array( $result ) ) { $result_array[]= "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' class='img'/></a>"; } $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" ); list($category_name) = mysql_fetch_array( $result ); mysql_free_result( $result ); $result_final = "<tr>\n\t<td> <span class='navlinks'><a href=viewgallery.php>Albums</a></span><font color=#ff0000> >> </font> <span class='navlinks'><a href=viewgallery.php?cid=$cid>$category_name</a></span><br><br/><br/><br/></td>\n</tr>\n"; foreach($result_array as $thumbnail_link) { if($counter == $number_of_thumbs_in_row) { $counter = 1; [b][size=24pt][size=18pt][b]$result_final .= "\n</tr>\n<tr>\n";[/b][/size][/size][/b] } else $counter++; [b][size=18pt] $result_final .= "\t<td>".$thumbnail_link."</td>\n";[/size][/b] } if($counter) { And my HTML output shows the tables like this... Code: [Select] <body> <table width='100%' border='0' align='center' style='width: 80%;'> <tr> <td> <span class='navlinks'><a href=viewgallery.php>Albums</a></span><font color=#ff0000> >> </font> <span class='navlinks'><a href=viewgallery.php?cid=1>Abstract</a></span><br><br/><br/><br/></td> </tr> <td><a href='viewgallery.php?cid=1&pid=240'><img src='photos/tb_240.jpg' border='0' alt='End Of Day' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=239'><img src='photos/tb_239.jpg' border='0' alt='A Photographer's Dream' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=238'><img src='photos/tb_238.jpg' border='0' alt='Heaven's View' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=237'><img src='photos/tb_237.jpg' border='0' alt='Colorful World ' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=241'><img src='photos/tb_241.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=242'><img src='photos/tb_242.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=243'><img src='photos/tb_243.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=244'><img src='photos/tb_244.jpg' border='0' alt='' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=245'><img src='photos/tb_245.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=246'><img src='photos/tb_246.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=247'><img src='photos/tb_247.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=248'><img src='photos/tb_248.jpg' border='0' alt='' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=249'><img src='photos/tb_249.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=250'><img src='photos/tb_250.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=251'><img src='photos/tb_251.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=252'><img src='photos/tb_252.jpg' border='0' alt='' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=253'><img src='photos/tb_253.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=254'><img src='photos/tb_254.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=255'><img src='photos/tb_255.jpg' border='0' alt='' class='img'/></a></td> </table> </body> Hi everyone! I am trying to figure out how to put echoed php results from mySQL database into a table ready for styling to look how i want it too. So far i have got to the point where the results are echoed out but they are not in a good table layout. (under "latest removalspace user's) I want it more structured in my table. I have found out how to create the table but just not been able to work out how to fit the echo's in without snytax errors??? the "new" table that i want to use is near the end of the script. Code: [Select] <?php // Make a MySQL Connection mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); // Retrieve all the data from the "example" table $result = mysql_query("SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies") or die(mysql_error()); // store the records into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "Name:\r".$row['company_name']; echo "\r\rLocation:\r".$row['location']; echo "\r\rPostcode:\r".$row['postcode']; echo "\r\nBasic Users:\r".$row['basicpackage_description']; echo "\r\nPremium Users:\r".$row['premiumuser_description']; echo "\r\nlogo:\r".$row['upload']; echo "<img src=\"http://www.removalspace.com/images/COMPANIES" . $row['upload'] . "\" alt=\"logo\" />"; echo "<table> <tr><th>Comppany Name</th><th>Location</th><th>Postcode</th><th>Basic Members</th><th>Upgraded Users</th><th>Company Logo</th></tr> <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>"; } ?> This is more than a question than anything else: I am looking for a tutorial or something that will allow me to make tables with php and mysql for example what I need is: mysql data: table = links lid = 1 lname = Page 1 linkid = page.php lid = 2 lname = Page 2 linkid = page2.php etc and i am try to get it so if there is 2 pages then the table would do Page 1 Page 2 if 3 Page 1 Page 2 Page 3 so there are 2 lname(s)s per row and 1 in each column and it would keep building the table and rows as more lname(s) are added. Does anybody know where to find a tutorial on doing something like this. Thanks in advance I want to read records from the database and print out in this table and I need help with the code. Code: [Select] <?php mysql_connect(localhost,root,""); mysql_select_db(oodb) or die( "Unable to select database"); $query=" SELECT * FROM oocust"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <HTML><HEAD> <script type="text/javascript"> var monthNames = [ "January","February","March","April","May","June","July", "August","September","October","November","December" ]; var today = new Date(); var mmyy = monthNames[today.getMonth()] + " / " + today.getFullYear(); </script> </HEAD><BODY bgcolor="#CCCC99" background="oldorchard.jpg"><b><center> <font size=+2><b> Old Orchard Invoice </font>Date: <script type="text/javascript">document.write(mmyy);</script></center> echo "<TABLE BORDER="0" CELLPADDING="5" CELLSPACING="5" background="oldorchard.jpg"> <TD> <TABLE BORDER="0" CELLPADDING="10" CELLSPACING="10" background="oldorchard.jpg"> <TD> <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" background="oldorchard.jpg"> <TD> <input type=text size=25 value="Old Orchard Plumbing"><br> <input type=text size=25 value="2210 E. Hogan Hollow Road"><br> <input type=text size=25 value="Margate, Fl 33063"><br></TD> <TR> <td> <input type=text size=3 value="Bill To:"><br> <input type=text size=25 value="$bname"><br> <input type=text size=25 value="$bstreet:">><br> <input type=text size=25 value="$bcity"><br> <input type=text size=25 value="$contact"><br></TD> <tr> <td> <input type=text size=5 value="Ship To:"><br> <input type=text size=25 value="$sname:"><br> <input type=text size=25 value="$street"><br> <input type=text size=25 value="$scity"></td> </TR> </TABLE> </TD> <TD> <input type=text size=25 value="Invoice No: $invnum"><br> <input type=text size=25 value="Date: $mm/dd/yyyy"><br> <input type=text size=25 value="Terms: $terms"><br> <input type=text size=25 value="Due Date: $duedate"><br> <input type=text size=25 value="Order No: $ordernum"><br> <input type=text size=25 value="Territory:"><br> <input type=text size=25 value="Salesperson:"><br> </TD> </TABLE> </TD> <TD align=center><img src="dave pic.jpg" width=250 height=350></td> </TABLE> echo "</tr>"; <hr> echo "</table>";mysql_close(); ?> </b></BODY></HTML> hey, i'm trying to select information from 2 tables in one query... so i have 2 tables... members - (holds the members information) looks like this: Code: [Select] +---+--------+------------+------------+ | id | name | email | password | +---+--------+------------+------------+ | 1 | user1 | 1@g.com | **** | | 2 | user2 | 2@g.com | **** | | 3 | user3 | 3@g.com | **** | | 4 | user4 | 4@g.com | **** | | 5 | user5 | 5@g.com | **** | | 6 | user6 | 6@g.com | **** | +---+--------+------------+------------+ the second table is profile_views which stores the profile views... Code: [Select] +---+--------+-----------+---------------+ | id | userid | viewerid | time | +---+--------+-----------+---------------+ | 1 | 4 | 1 | 1287949172 | | 2 | 6 | 2 | 1287949172 | | 3 | 2 | 4 | 1287949172 | | 4 | 4 | 5 | 1287949172 | | 5 | 3 | 2 | 1287949172 | +---+--------+-----------+---------------+ userid - the profile (member) id that been watched viewerid - the id of the member who watched time - the time this happened im trying to select from profile_views the viewers ids' and select the info from the members according to the viewerid, but also i want to select the time from the profile_views, so it's should look like this: Code: [Select] +---+--------+------------+----------+------------+ | id | name | email | password | time +---+--------+------------+----------+------------+ | 1 | user1 | 1@g.com | **** | 1287949172 | 2 | user2 | 2@g.com | **** | 1287949172 | 3 | user3 | 3@g.com | **** | 1287949172 | 4 | user4 | 4@g.com | **** | 1287949172 | 5 | user5 | 5@g.com | **** | 1287949172 | 6 | user6 | 6@g.com | **** | 1287949172 +---+--------+------------+----------+------------+ this is my code: Code: [Select] $DB->query("SELECT viewerid FROM profile_views WHERE userid={$core->input['showuser']} ORDER BY time DESC LIMIT 5"); if ( $DB->get_num_rows() > 0 ) { while ( $all_viewers = $DB->fetch_row() ) { $viewers_ids[] = $all_viewers['viewerid']; } $viewers_ids = implode(",", $viewers_ids); $DB->query("SELECT m.*, v.* FROM members m LEFT JOIN profile_views v ON (v.userid=m.id) WHERE m.id IN ({$viewers_ids})"); while ( $viewers = $DB->fetch_row() ) { } } but it's just dont work! any ideas? Thanks in advance! i have 2 tables. table 1 - Id -Name -ShortId table 2 -lots of data.... -Category (same value with table1 Id) im trying to join this 2 tables... Code: [Select] $query = "SELECT * FROM tblnews_categories WHERE ShortId != 0 ORDER BY `ShortId`"; $result = mysql_query($query); $query2 = "SELECT * FROM tblnews_categories, tblnews WHERE tblnews_categories.Id = tblnews.Category "; $result2 = mysql_query($query2); while($row = mysql_fetch_assoc($result)) { ?> <div class="quartetin2"> <div id="HomeMoreNewsIMG2"><div id="HomeMoreNewsTitle2"><a href="summary?catid=19167"><?php echo strtoupper($row['Name']);?></a></div></div> <div id="HomeMoreNewsText"> <?php while($row2 = mysql_fetch_assoc($result2)) { ?> <tr> <td id="HomeLatestNewsDate"><li><?php echo strtoupper($row2['Title']);?></li></td> </tr> <?php } ?> What i want to do is when Id = Category echo all data under the specific category this is the problem i have 2 tables table named ZAMJENE with fields id_event_1, id_event_2 table named EVENTS with fields id_event and event_date and i need echo $id_event_1 on date(EXTRACT FROM TABLE EVENTS FIELD event_date) can be replaced with $id_event_2 on date(EXTRACT FROM TABLE EVENTS FIELD event_date) structure must remains because i have half site build already and i have 3rd table where i just need use JOIN hope you understand problem I am entering a question and notes into one table and creating an ID number in Table 1: $qid (Question ID) $question $notes I am then entering an answer and creating an ID for the answer which sites next to question ID in Table 2: $aid (Answer ID) $answer I am now trying to transfer the Question ID into Table 2. I am currently trying to do this as a hidden string: <input name="category" type="hidden" value="$qid" id="qid" > Does any one have any advice on how I can use two fields. Can I display or insert data with the same php script? |