PHP - Display Mysql Results As 3 Column Table
Hey Everyone,
I'm creating a site that will show images uploaded for certain days working on a job site. Kind of a day-to-day photo journal for the customer. On the site, the user gets here, sees 3 large images, and a series of thumbnails if more than 3 images exist for that day (works fine). However, underneath that I want to display a 3-4 column setup of "Archived Dates" that provide a link to the images of the other dates. I have this working correctly, but the results are displayed as follows: Date 1: Date 2: Date 3: etc.... I want them to display like this; Day 1 Day 4 Day 2 Day 5 Day 3 Day 6 and so on..... in a 3 column format. Here is the code I have right now just looping through to display these link results, not the rest of the page. I am trying to do it tableless right now, but if that isn't the right way to go, please let me know. Thanks to anyone in advance, Nick $SQLRowe = "SELECT DISTINCT RoweImgDate from tblRowe WHERE RoweImgDate !='" . $_GET['date'] . "' Order by RoweImgDate DESC Limit 0, 30"; //echo $SQLRowe; $rsSQLRowe = mysql_query($SQLRowe); <span class="rowe">Archived Photos:</span><br/> <div id="archive"> <?php while($row = mysql_fetch_array($rsSQLRowe)){ //echo "<a href='index.php?id="' . $row[RoweImgID] . '"' class='link'>$row[RoweImgDate]</a></br>"; echo "<div id='archivedates'>"; echo "<a href='index.php?date=" . $row[RoweImgDate] . "' class='link'>$row[RoweImgDate]</a>"; echo "</div>"; //echo "<img src='images/$row[RoweImage]'/><br/>"; //echo "<span class='FeatDesc'><p>$row[RoweImgDesc]</p></span><br/>"; } ?> </div> Similar TutorialsI have the following code that searches my database and displays results in a table: $fields = array("field1", "field2", "field3") $cols = implode (', ', $fields); $result= mysql_query (" SELECT $cols FROM tablename WHERE ................... "); if (!$result) {die('Could not search database: ' . mysql_error());} if($result) { if(mysql_num_rows($result) == 0) { return "Sorry. No records found in the database"; } else { $table = "<table border='1' cellpadding='5' cellspacing='5'>"; while($arr = mysql_fetch_array($result, MYSQL_ASSOC)) { $table .= "\t\t<tr>\n"; foreach ($arr as $val_col) { $table .= "\t\t\t".'<td>'.$val_col.'</td>'."\n"; } $table .= "\t\t</tr>\n"; } $table .= "</table>"; echo $table; } mysql_free_result($result); } As you can see each of the MySQL table fields specified by $fields is displayed in a new column in the html table. I want to change this so that e.g. "field3" is displayed in a new row instead. So, instead of the html table looking like: | "field1-result1" | "field2-result1" | "field3-result1" | | "field1-result2" | "field2-result2" | "field3-result2" | | "field1-result3" | "field2-result3" | "field3-result3" | I want it to look like: | "field1-result1" | "field2-result1" | | "field3-result1" | | | "field1-result2" | "field2-result2" | | "field3-result2" | | | "field1-result3" | "field2-result3" | | "field3-result3" | | I guess this is quite straightforward, but I can't work it out! Pls help! Thanks. Hi, I'm quite new to this and I'm trying to get this to line up in a table with 3 columns (unlimited rows) I have searched and tried but I'm not having any luck. Can any one help? Thank you Code: [Select] <?php echo '<div class="resultados_sub_cat">'; foreach($this->subcats as $key => $subcat) { $subcat->link = JRoute::_('index.php?option=classcliff&view=list&catid='.$subcat->id."&Itemid=".$this->Itemid); if ($key != 0) echo ' - '; echo '<a href="'.$subcat->link.'">'.$subcat->name.'</a>'; } ?> I have been trying to work out how to get my results into a 3 column layout using css and not using tables in any way. I found the code for tables: echo '<table>'; $counter = 0; $cells_per_row = 3; while($row=mysql_fetch_array($result)) { $counter++; if(($counter % $cells_per_row) == 1) { echo '<tr>'; } echo '<td>' . (whatever you echo from your $row array) . '</td>'; if(($counter % $cells_per_row) == 0) { echo '</tr>'; } } // just in case we haven't closed the last row // this would happen if our result set isn't divisible by $cells_per_row if(($counter % $cells_per_row) != 0) { echo '</tr>'; } echo '</table>'; How Can I adapt this or how should I use divs here? I am fine with the css code, just need to work out how to get the 3 column layout correct in the loop. Hi everyone, I'm having real problems trying to retrieve database records in a 3 column layout, I got there eventually with a huge amount of help. Unfortunately the code will only display records that are divisable by by three; for example for a database table that has 45 records there is no problem, as all records can be displayed in a 3 column layout. However if the table contains 47 records it won't display the 2 odd records. My php skills are limited so I need all the help I can get. I'm a bit desperate to sort this out for a project I'm doing, any help would be greatly appreciated - here is the php code: $total = count($records); $nocol = 3; $norows = $total / $nocol; for ($i=1; $i <= $norows; $i++) { $cell = 0; echo "<tr>"; for($col=1; $col <= $nocol; $col++) { echo "<td>"; if ($col == 1) { $cell += $i; echo '<strong class="navtext">'.$records[$cell - 1]['ret_name'].'</strong><br />'; echo $records[$cell - 1]['ret_add1'].'<br />'; echo $records[$cell - 1]['ret_add2'].'<br />'; echo $records[$cell - 1]['ret_town'].'<br />'; echo $records[$cell - 1]['ret_county'].'<br />'; echo $records[$cell - 1]['ret_pcode'].'<br />'; echo $records[$cell - 1]['ret_phone'].'<br />'; echo $records[$cell - 1]['ret_email'].'<br />'; echo $records[$cell - 1]['ret_web'].'<br />'; } else { $cell += $norows; echo '<strong class="navtext">'.$records[$cell - 1]['ret_name'].'</strong><br />'; echo $records[$cell - 1]['ret_add1'].'<br />'; echo $records[$cell - 1]['ret_add2'].'<br />'; echo $records[$cell - 1]['ret_town'].'<br />'; echo $records[$cell - 1]['ret_county'].'<br />'; echo $records[$cell - 1]['ret_pcode'].'<br />'; echo $records[$cell - 1]['ret_phone'].'<br />'; echo $records[$cell - 1]['ret_email'].'<br />'; echo $records[$cell - 1]['ret_web'].'<br />'; } echo"</td>"; } echo"</tr>"; } I'm also trying to paginate the results, is this actually possible when using a three column layout? I look forward to any suggestions. My Php Buddies, I have mysql tbl columns these:
id: Now, I want to display their row data by excluded a few columns. Want to exclude these columns: date_&_time account_activation_code account_activation_status id_verification_video_file_url password
So, the User's (eg. your's) homepage inside his account should display labels like these where labels match the column names but the underscores are removed and each words' first chars CAPITALISED:
Id: 1
For your convenience only PART 1 works. Need help on Part 2 My attempted code:
PART 1 <?php // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Query to get columns from table $query = $conn->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'members' AND TABLE_NAME = 'users'"); while($row = $query->fetch_assoc()){ $result[] = $row; } // Array of all column names $columnArr = array_column($result, 'COLUMN_NAME'); foreach ($columnArr as $value) { echo "<b>$value</b>: ";?><br><?php } ?> PART 2 <?php //Display User Account Details echo "<h3>User: <a href=\"user.php?user=$user\">$user</a> Details</h3>";?><br> <?php $excluded_columns = array("date_&_time","account_activation_code","account_activation_status","id_verification_video_file_url","password"); foreach ($excluded_columns as $value2) { echo "Excluded Column: <b>$value2</b><br>"; } foreach ($columnArr as $value) { if($value != "$value2") { $label = str_replace("_"," ","$value"); $label = ucwords("$label"); //echo "<b>$label</b>: "; echo "$_SESSION[$value]";?><br><?php echo "<b>$label</b>: "; echo "${$value}";?><br><?php } } ?> PROBLEM: Columns from the excluded list still get displayed. Edited November 19, 2018 by phpsaneHey all, first post to this site. I'm somewhat new to PHP, so bear with me - this might be an easy question, it might not be. Just looking for a little help. Basically, I have a query which takes commands from a form through AJAX (day, time, time1). The query executes a wildcard on a table named sip_data, searches for linked $id (so if $id=3, for example in multiple tables, it spits out the $name, $zip in a div). Here's the code: Code: [Select] <?php $dbhost = "localhost"; $dbuser = ""; $dbpass = ""; $dbname = ""; //Connect to MySQL Server $link = mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $id = $_GET['id']; $name = $_GET['name']; $zip = $_GET['zip']; $server_url = $_GET['server_url']; $day = $_GET['day']; $time = $_GET['time']; $time1 = $_GET['time1']; // Escape User Input to help prevent SQL Injection $id = mysql_real_escape_string($id); $name = mysql_real_escape_string($name); $zip = mysql_real_escape_string($zip); $server_url = mysql_real_escape_string($server_url); $day = mysql_real_escape_string($day); $time = mysql_real_escape_string($time); $time1 = mysql_real_escape_string($time1); //build query $query = "SELECT * FROM $day,sip_data WHERE $day.id=sip_data.id AND $day$time<=>$day$time1 ORDER BY zip ASC"; //Execute query $qry_result = mysql_query($query) or die(('No Results')); //Build Result String while($row = mysql_fetch_array($qry_result)) { echo "<table id=query_result align=left>"; echo "<tr>"; if($zip = $row[zip]); echo "<th><b>$row[zip]</b></th>"; echo "</tr>"; echo "<tr>"; echo "<td><a href=$row[server_url] rel=ajaxDiv>$row[name]</a></td>"; echo "</tr>"; echo "</table>"; } echo $display_string; ?> Basically, my issue with this is that some of the results within the sip_data DB will have zip codes that repeat. The current code prints out each results with the zip code and name - here's an image of a sample result: What I would like to do is avoid repeating the zip code and just group the results under each zip code, kinda like this: 55408 55412 55423 --------- ------------ ---------- example example example example example example Any help would be greatly appreciated. I feel like I'm so close to the answer, but just need a little guidance. Who knows, I might be way off. Thanks in advance! I have a database with one row and about 50 columns, where the inserted data is being displayed on a page. But a lot of the time not all columns are being used. So say only 25 columns have data, there will be 25 blanks spaces with an • symbol. Is there a way to ignore to columns that have no data in them? Such as SELECT * from notices WHERE [columns have data] Code: [Select] <?php $html="<table>"; $q="select * from notices"; $r=mysql_query($q); while($o=mysql_fetch_object($r)){ foreach($o as $key=>$val){ $html.="<tr><td colspan='2' bgcolor='#896B45'><div style='padding:10px;'>&#8226; {$val}<br></div></td></tr>"; }} $html.="</table>"; echo $html; ?> CREATE TABLE `notices` ( `id` int(11) NOT NULL auto_increment, `notice1` text, `notice2` text, `notice3` text, `notice4` text, `notice5` text, `notice6` text, `notice7` text, `notice8` text, `notice9` text, `notice10` text, `notice11` text, `notice12` text, `notice13` text, `notice14` text, `notice15` text, `notice16` text, `notice17` text, `notice18` text, `notice19` text, `notice20` text, `notice21` text, `notice22` text, `notice23` text, `notice24` text, `notice25` text, `notice26` text, `notice27` text, `notice28` text, `notice29` text, `notice30` text, `notice31` text, `notice32` text, `notice33` text, `notice34` text, `notice35` text, `notice36` text, `notice37` text, `notice38` text, `notice39` text, `notice40` text, `notice41` text, `notice42` text, `notice43` text, `notice44` text, `notice45` text, `notice46` text, `notice47` text, `notice48` text, `notice49` text, `notice50` text, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=40 DEFAULT CHARSET=utf8 I have an admin page for the posting of the date to the database: Code: [Select] <?php include_once($_SERVER["DOCUMENT_ROOT"] . "/main.inc.php"); $page_content = db_select("select * from notices"); $pc = $page_content[0]; $ff=$_POST; if ($ff['submit']) { $insc="UPDATE notices SET notice1='".$ff['notice1']."' , notice2='".$ff['notice2']."' , notice3='".$ff['notice3']."' , notice4='".$ff['notice4']."' , notice5='".$ff['notice5']."' , notice6='".$ff['notice6']."' , notice7='".$ff['notice7']."' , notice8='".$ff['notice8']."' , notice9='".$ff['notice9']."' , notice10='".$ff['notice10']."' , notice11='".$ff['notice11']."' , notice12='".$ff['notice12']."' , notice13='".$ff['notice13']."' , notice14='".$ff['notice14']."' , notice15='".$ff['notice15']."' , notice16='".$ff['notice16']."' , notice17='".$ff['notice17']."' , notice18='".$ff['notice18']."' , notice19='".$ff['notice19']."' , notice20='".$ff['notice20']."' , notice21='".$ff['notice21']."' , notice22='".$ff['notice22']."' , notice23='".$ff['notice23']."' , notice24='".$ff['notice24']."' , notice25='".$ff['notice25']."' , notice26='".$ff['notice26']."' , notice27='".$ff['notice27']."' , notice28='".$ff['notice28']."' , notice29='".$ff['notice29']."' , notice30='".$ff['notice30']."' , notice31='".$ff['notice31']."' , notice32='".$ff['notice32']."' , notice33='".$ff['notice33']."' , notice34='".$ff['notice34']."' , notice35='".$ff['notice35']."' , notice36='".$ff['notice36']."' , notice37='".$ff['notice37']."' , notice38='".$ff['notice38']."' , notice39='".$ff['notice39']."' , notice40='".$ff['notice40']."' , notice41='".$ff['notice41']."' , notice42='".$ff['notice42']."' , notice43='".$ff['notice43']."' , notice44='".$ff['notice44']."' , notice45='".$ff['notice45']."' , notice46='".$ff['notice46']."' , notice47='".$ff['notice47']."' , notice48='".$ff['notice48']."' , notice49='".$ff['notice49']."' , notice50='".$ff['notice50']."' , id='1' WHERE id='1'"; mysql_query($insc); } ?> <html> <head> </head> <body> <form name="noticesform" method="post" action="notices_admin.php" enctype="multipart/form-data"> <textarea name='notice1' cols='110' rows='3' class='input'><?=$pc["notice1"]?> </textarea> <textarea name='notice2' cols='110' rows='3' class='input'><?=$pc["notice2"]?> </textarea> <textarea name='notice3' cols='110' rows='3' class='input'><?=$pc["notice3"]?> </textarea> <textarea name='notice4' cols='110' rows='3' class='input'><?=$pc["notice4"]?> </textarea> <textarea name='notice5' cols='110' rows='3' class='input'><?=$pc["notice5"]?> </textarea> <textarea name='notice6' cols='110' rows='3' class='input'><?=$pc["notice6"]?> </textarea> <textarea name='notice7' cols='110' rows='3' class='input'><?=$pc["notice7"]?> </textarea> <textarea name='notice8' cols='110' rows='3' class='input'><?=$pc["notice8"]?> </textarea> <textarea name='notice9' cols='110' rows='3' class='input'><?=$pc["notice9"]?> </textarea> <textarea name='notice10' cols='110' rows='3' class='input'><?=$pc["notice10"]?> </textarea> <textarea name='notice11' cols='110' rows='3' class='input'><?=$pc["notice11"]?> </textarea> <textarea name='notice12' cols='110' rows='3' class='input'><?=$pc["notice12"]?> </textarea> <textarea name='notice13' cols='110' rows='3' class='input'><?=$pc["notice13"]?> </textarea> <textarea name='notice14' cols='110' rows='3' class='input'><?=$pc["notice14"]?> </textarea> <textarea name='notice15' cols='110' rows='3' class='input'><?=$pc["notice15"]?> </textarea> <textarea name='notice16' cols='110' rows='3' class='input'><?=$pc["notice16"]?> </textarea> <textarea name='notice17' cols='110' rows='3' class='input'><?=$pc["notice17"]?> </textarea> <textarea name='notice18' cols='110' rows='3' class='input'><?=$pc["notice18"]?> </textarea> <textarea name='notice19' cols='110' rows='3' class='input'><?=$pc["notice19"]?> </textarea> <textarea name='notice20' cols='110' rows='3' class='input'><?=$pc["notice20"]?> </textarea> <textarea name='notice21' cols='110' rows='3' class='input'><?=$pc["notice21"]?> </textarea> <textarea name='notice22' cols='110' rows='3' class='input'><?=$pc["notice22"]?> </textarea> <textarea name='notice23' cols='110' rows='3' class='input'><?=$pc["notice23"]?> </textarea> <textarea name='notice24' cols='110' rows='3' class='input'><?=$pc["notice24"]?> </textarea> <textarea name='notice25' cols='110' rows='3' class='input'><?=$pc["notice25"]?> </textarea> <textarea name='notice26' cols='110' rows='3' class='input'><?=$pc["notice26"]?> </textarea> <textarea name='notice27' cols='110' rows='3' class='input'><?=$pc["notice27"]?> </textarea> <textarea name='notice28' cols='110' rows='3' class='input'><?=$pc["notice28"]?> </textarea> <textarea name='notice29' cols='110' rows='3' class='input'><?=$pc["notice29"]?> </textarea> <textarea name='notice30' cols='110' rows='3' class='input'><?=$pc["notice30"]?> </textarea> <textarea name='notice31' cols='110' rows='3' class='input'><?=$pc["notice31"]?> </textarea> <textarea name='notice32' cols='110' rows='3' class='input'><?=$pc["notice32"]?> </textarea> <textarea name='notice33' cols='110' rows='3' class='input'><?=$pc["notice33"]?> </textarea> <textarea name='notice34' cols='110' rows='3' class='input'><?=$pc["notice34"]?> </textarea> <textarea name='notice35' cols='110' rows='3' class='input'><?=$pc["notice35"]?> </textarea> <textarea name='notice36' cols='110' rows='3' class='input'><?=$pc["notice36"]?> </textarea> <textarea name='notice37' cols='110' rows='3' class='input'><?=$pc["notice37"]?> </textarea> <textarea name='notice38' cols='110' rows='3' class='input'><?=$pc["notice38"]?> </textarea> <textarea name='notice39' cols='110' rows='3' class='input'><?=$pc["notice39"]?> </textarea> <textarea name='notice40' cols='110' rows='3' class='input'><?=$pc["notice40"]?> </textarea> <textarea name='notice41' cols='110' rows='3' class='input'><?=$pc["notice41"]?> </textarea> <textarea name='notice42' cols='110' rows='3' class='input'><?=$pc["notice42"]?> </textarea> <textarea name='notice43' cols='110' rows='3' class='input'><?=$pc["notice43"]?> </textarea> <textarea name='notice44' cols='110' rows='3' class='input'><?=$pc["notice44"]?> </textarea> <textarea name='notice45' cols='110' rows='3' class='input'><?=$pc["notice45"]?> </textarea> <textarea name='notice46' cols='110' rows='3' class='input'><?=$pc["notice46"]?> </textarea> <textarea name='notice47' cols='110' rows='3' class='input'><?=$pc["notice47"]?> </textarea> <textarea name='notice48' cols='110' rows='3' class='input'><?=$pc["notice48"]?> </textarea> <textarea name='notice49' cols='110' rows='3' class='input'><?=$pc["notice49"]?> </textarea> <textarea name='notice50' cols='110' rows='3' class='input'><?=$pc["notice50"]?> </textarea> <input type="submit" name="submit" value="Click here to update" class="input"> </form> </body> </html> hi, i'm new in php/mysql. i'm stored student marks values in following format in mysql db table. id student_code Tamil English Maths Science Social 1 1 100 75 78 88 95 2 2 85 90 88 80 100 But i want to search and display the specific student marks in following format. id:1 student_code:1 Tamil:100 English:75 Maths:78 Science:88 Social:92 Total:? Avg:? please give correct code for this format. I am trying to display certain MySQL data based off of what link is clicked. For example.. I want to display all the entries from 2009 when a link for 2009 is clicked; maybe like.. <a href="http://website.com/page?yr=09">2009</a> But I am having trouble doing so.. any help would be great! P.S. The years are in my database with only the last two numbers.. 10, 09, 08, etc. $result = mysql_query("select setlist_id, month, day, year, name, venue, location, label1, set1, set2, set3, encore, notes, photos, recording, poster from $database_table order by setlist_id DESC, year, month, day",$db) or die_now("Could not select setlists"); while($row = mysql_fetch_array($result)) { $the_id = $row["setlist_id"]; $the_month = $row["month"]; $the_day = $row["day"]; $the_year = $row["year"]; $the_name = $row["name"]; $the_venue = $row["venue"]; $the_location = $row["location"]; $the_label1 = $row["label1"]; $the_set1 = $row["set1"]; $the_set2 = $row["set2"]; $the_set3 = $row["set3"]; $the_encore = $row["encore"]; $the_notes = $row["notes"]; $the_photos = $row["photos"]; $the_recording = $row["recording"]; $the_poster = $row["poster"]; echo("<div class='date' id='date' tabindex='0'>" . "$the_month" . "." . "$the_day" . "." . "$the_year" . " - "); echo ($the_name != '') ? "" . "$the_name" . " - " : ''; echo("" . "$the_venue" . " - " . "$the_location" . "</div>"); echo("<div class='set'>" . "$the_label1" . ":<br /></div><div class='list'>" . "$the_set1" . "<br /></div>"); echo ($the_set2 != '') ? "<div class='set'>Set Two:<br /></div><div class='list'>" . "$the_set2" . "<br /></div>" : ''; echo ($the_set3 != '') ? "<div class='set'>Set Three:<br /></div><div class='list'>" . "$the_set3" . "<br /></div>" : ''; echo ($the_encore != '') ? "<div class='set'>Enco <br /></div><div class='list'>" . "$the_encore" . "<br /></sdiv>" : ''; echo("<div class='line'></div>"); echo nl2br("<div class='notes'>" . "$the_notes" . "</div>"); } When I replace the $result line with... $result = mysql_query("SELECT * FROM `$database_table` WHERE `year` = '09' order by setlist_id DESC, year, month, day",$db) or die_now("Could not select shows");... I get all the results from just 2009, which is what I want, but I want the results to depend on what link has been clicked. I hope I am making sense. Hi I have the following code: Code: [Select] $result = mysql_query("SELECT * FROM xbox_games order by gameid"); $row = mysql_fetch_assoc($result); $id = $row["gameid"]; $title = $row["gametitle"]; $cover = $row["cover"]; <?php echo $title;?> Which displays only the first result from my database. How can i change this to display all the results either as a list, or in a table? Thanks Hello, I know this should be pretty simple to figure out, but everything I try is giving me absolutely no results. I have a mysql query selecting columns from my database and returning results. I have the results printing out right now, so I can see that this part is working. All I want to do is take the results and put them into a table to display on my page. Basically, take what's in the database table and copy it to a table I can put on the web. FYI I am using sourcerer so the "connect" code is taken care of for me in the "JFactory" bit of code. Here is the first part of my code, selecting the information from the database. {source} <?php $db = JFactory::getDbo(); $query = $db -> getQuery(true); $query -> SELECT($db -> quoteName(array('first_dept_name', 'last_name', 'dept', 'position', 'phone_num'))); $query -> FROM ($db -> quoteName('#__custom_contacts')); $query -> ORDER ('first_dept_name DESC'); $query -> WHERE ($db -> quoteName('contact_category')."=".$db -> quote('YTown Employees')); $db -> setQuery($query); $results = $db -> loadObjectList(); print_r($results); Here is where I am trying to print the results into a table. I got this code directly from a PHP book, but I am getting nothing at all returned back to me. I get table headers, but no data. <?php echo "<table><tr><th>Name</th><th>Department</th></tr>"; while ($row = mysqli_fetch_array ($result)){ echo "<tr>"; echo "<td>".$row['last_name']."</td>"; echo "<td>".$row['dept']."</td>"; echo "</tr>"; } echo "</table>"; ?> {/source} Say a user puts in a support request, and for every request it generates a unqiue string, and enters it into the database. Ok, now say there is a text field, when the user enters their unique string and it finds a match, it displays the data along with it. How can I accomplish this? Im kind of new to mysql, but I know basic SQL. Would be great if somebody could point me in the right direction! Thanks First off, let me say that this will not be a public use site. We want to create a site that allows us to run queries in our database; this way we don't need to log into the MySQL server when ever we want to run a query. Basically, I am trying to create something as simple as a form with a text-input and a submit button. In this text-input, we will write a query (such as SELECT * FROM xxxx). When we hit submit, we would like to have the MySQL table printed out in a large textbox below. Our database has multiple tables, so something that works across the entire database seamlessly is key. Has anyone ever made anything like this? Is there another way to go about this? We really just want an easy way to run queries on the go. Thanks in advance to anyone who replies! I have a mysql table named songs with 3 columns, id, artist,title. Most of the songs in the artist column are correct, ex: artist ------------------ John Denver Loretta Lynn Shania Twain Luke Bryan But some of the songs in the artist column are reveresed with a comma, ex: artist ----------------- Dever, John Lynn. Loretta Twain, Shania Bryan, Luke Is there an easy php code snippet or mysql statement that i can use to reverse the order of first name and last name and remove the comma in the last example so the artst columd matches the first example? I hope this makes sense, thanks, Dale. Hi guys I hope I am in the right place on this forum, if not I apologise. A have been working with CS-Cart and had so much trouble trying to update product combinations so I searched for help on the data feeds I am using and found that there was a script that would update my products for os-commerce, this has worked out even worse. All I really need is for a script to update one column called amount in a Mysql table by referring to the product_code column, Eg If product_code NS324 is= to 5 ad 5 to the amount column. This sounds simple but I think it might be complex. Here is the Table Generated b\: phpM\Admin 3.4.9 / M\SQL 5.5.20-log SQL quer\: SELECT * FROM `cscart_product_options_inventor\` LIMIT 0, 30 ; Rows: 30 Column1-----------Column2---------------Column3--------------Column4----------Column5-------Column6-------Column7 product_id-----product_code---------combination_hash-----combination-------amount----------temp-----------position --29813--------------NS3455----------- --1447985068-----------738_3059-----------0-----------------N-------------------0 So if I can update the amount column using the product_code would solve all of my problems. So this is what I need to do, I need to add an amount to the amount column related to the product_code NS3455 or update amount or even replace amount it don't matter. Due to the nature of the feeds I receive I cannot use product_id or combination_hash or combination. Please help me do this. Lets see who is the clever one. Thanks for you time I have a table of restaurant menu items called menu_items. This table has a float row(3,2) called price. I have a query that looks like this: $query = mysql_query("SELECT * FROM menu_items WHERE restaurant = '".$restaurantid."'"); How would I find the average of the price row from that query? Basically I want to find the average item price for a restaurants menu. Hi all, I have a table... id | Name | Downloads | 01 | tom | 5 02 | thomas | 2 03 | tommy | 15 I need a button in my page whcih on submit would resent the 'downloads' column so all values are set to 0, Is this possible and how if it is? Thanks for any advice Hey guys, I'm a little confused to how I can do this.
I am basically wanting to give my first column a 'NOT NULL AUTO_INCREMENT' and give each row it's own 'id'. The issue I am having is that the script I am using truncates the whole SQL table with a CSV file that is cron'd daily to update data.
I am currently using this script:
<?php $databasehost = "localhost"; $databasename = ""; $databasetable = ""; $databaseusername=""; $databasepassword = ""; $fieldseparator = ","; $lineseparator = "\n"; $enclosedbyquote = '"'; $csvfile = "db-core/feed/csv/csv.csv"; if(!file_exists($csvfile)) { die("File not found. Make sure you specified the correct path."); } try { $pdo = new PDO("mysql:host=$databasehost;dbname=$databasename", $databaseusername, $databasepassword, array( PDO::MYSQL_ATTR_LOCAL_INFILE => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); } catch (PDOException $e) { die("database connection failed: ".$e->getMessage()); } $pdo->exec("TRUNCATE TABLE `$databasetable`"); $affectedRows = $pdo->exec(" LOAD DATA LOCAL INFILE ".$pdo->quote($csvfile)." REPLACE INTO TABLE `$databasetable` FIELDS OPTIONALLY ENCLOSED BY ".$pdo->quote($enclosedbyquote)." TERMINATED BY ".$pdo->quote($fieldseparator)." LINES TERMINATED BY ".$pdo->quote($lineseparator)." IGNORE 1 LINES"); echo "Loaded a total of $affectedRows records from this csv file.\n"; ?>Is it possible to amend this script to ignore my first column and truncate all of the data in the table apart from the first column? I could then give all of the rows in the first column their own ID's any idea how I could do this? I am still very nooby so please go easy on me Hey all I'm working on an auction website. I've added a new column to the 'Auctions' table, however the 'sell.php' page now does not work with this new column (I've deleted the column and tested again and it works, so that's definitely the cause). The new column can not be in a separate table as it needs to pull 'id' values from the 'Auctions' table for various functions. My question to you is, is there any PHP snippet I can use to tell sell.php to stop reading the 'Auctions' table once it reaches the column I've added? The new column is called 'shipped' if that's of any relevance. Below is some of the PHP I'm working on on the sell.php page. #//Populate arrays $UPLOADED_PICTURES[] = $file; $UPLOADED_PICTURES_SIZE[] = filesize($image_upload_path.session_id()."/".$file); } } } $_SESSION["UPLOADED_PICTURES"] = $UPLOADED_PICTURES; $_SESSION["UPLOADED_PICTURES_SIZE"] = $UPLOADED_PICTURES_SIZE; $_SESSION["GALLERY_UPDATED"]=true; if($sessionVars['SELL_action']=='edit') { $sessionVars["OLD_GALLERYFEE"] = $SETTINGS["picturesgalleryvalue"] * count($UPLOADED_PICTURES); } else { $sessionVars["OLD_GALLERYFEE"] = 0; } } } } $with_reserve = $sessionVars["SELL_with_reserve"]; $reserve_price = $sessionVars["SELL_reserve_price"]; $minimum_bid = $sessionVars["SELL_minimum_bid"]; $duration_hours = $sessionVars["SELL_duration_hours"]; $duration_minutes = $sessionVars["SELL_duration_minutes"]; $pict_url=$sessionVars["SELL_pict_url"]; $imgtype = $sessionVars["SELL_file_uploaded"]; $title = $sessionVars["SELL_title"]; $description = stripslashes($sessionVars["SELL_description"]); $pict_url = $sessionVars["SELL_pict_url"]; $atype = $sessionVars["SELL_atype"]; $adultonly = $sessionVars["SELL_adultonly"]; $TPL_item_value = $item_value = $sessionVars["SELL_item_value"]; $TPL_number_of_bids =$number_of_bids=$sessionVars["SELL_number_of_bids"]; $TPL_bid_value = $bid_value = $sessionVars["SELL_bid_value"]; $iquantity = $sessionVars["SELL_iquantity"]; $buy_now = $sessionVars["SELL_with_buy_now"]; $buy_now_price = $sessionVars["SELL_buy_now_price"]; $duration = $sessionVars["SELL_duration"]; $duration_second = $sessionVars["SELL_duration_second"]; $minimum_users = $sessionVars["SELL_minimum_users"]; $relist = $sessionVars["SELL_relist"]; $increments = $sessionVars["SELL_increments"]; $customincrement = $sessionVars["SELL_customincrement"]; $international = ($sessionVars["SELL_international"])?"on":""; $sellcat = $_SESSION['sellcat']; $private = $sessionVars["SELL_private"]; if($private != 'y') $private = 'n'; $sendemail = $sessionVars["SELL_sendemail"]; $txt = $sessionVars["SELL_txt"]; $num = $sessionVars["SELL_num"]; $buy_now_only = $sessionVars["SELL_buy_now_only"]; and... $auction_id=$sessionVars['SELL_auction_id']; } elseif ($sessionVars["SELL_action"] == "reopen") { $query = "UPDATE BPLA_auctions set title = '".addslashes($sessionVars["SELL_title"])."', starts = '".$a_starts."', starts_second = '".$a_starts_second."', description = '".addslashes($sessionVars["SELL_description"])."', pict_url = '".addslashes($sessionVars["SELL_pict_url"])."', category = ".$sessionVars["SELL_sellcat"].", minimum_bid = '".$sessionVars["SELL_minimum_bid"]."', reserve_price = '".(($sessionVars["SELL_with_reserve"]=="yes")?$sessionVars["SELL_reserve_price"]:"0")."', buy_now = '".(($sessionVars["SELL_with_buy_now"]=="yes")?$sessionVars["SELL_buy_now_price"]:"0")."', bn_only = '".$sessionVars["SELL_buy_now_only"]."', auction_type = '".$sessionVars["SELL_atype"]."', adultonly = '".$sessionVars["SELL_adultonly"]."', duration = '".$sessionVars["SELL_duration"]."', duration_second = '".$sessionVars["SELL_duration_second"]."', minimum_users = ".intval($sessionVars["SELL_minimum_users"]).", increment = ".doubleval($sessionVars["SELL_customincrement"]).", international = '".(($sessionVars["SELL_international"])?"1":"0")."', ends = '".$a_ends."', ends_second = '".$a_ends_second."', photo_uploaded = ".(($sessionVars["SELL_file_uploaded"])?"1":"0").", quantity = ".$sessionVars["SELL_iquantity"].", relist=".intval($sessionVars["SELL_relist"]).", relisted=0, closed='0', private='n', item_value = '".$sessionVars["SELL_item_value"]."', number_of_bids = '".$sessionVars["SELL_number_of_bids"]."', bid_value = '".$sessionVars["SELL_bid_value"]."', suspended='".$SUSPENDED."',"; $query .= "current_bid=0, num_bids=0, WHERE id = '".$sessionVars["SELL_auction_id"]."'"; $backtoclosed=true; if($BPLowbidAuction_TESTMODE == 'yes'){ echo $ERR = $ERR_9999; }else{ $res=mysql_query($query); if (!$res) { MySQLError($query); exit; } $auction_id=$sessionVars['SELL_auction_id']; $sessionVars["SELL_auction_id_old"]=$auction_id; $query = "DELETE FROM BPLA_bids WHERE auction='$auction_id'"; $res = @mysql_query($query); if(!$res) { MySQLError($query); exit; } Thanks in advance for any help and replies! I was wondering how does one go about showing results from SELECT query in columns in a html table. I have a list of products in a table, and would like to show them on the page in 4 columns. I have done many searches on google to try and find the sulution, but the majority of what im finding instead is about displaying a table from phpmyadmin as a table in html. If its a large operation to do this, I would be very happy if someone could poiint me in the direction of a tutorial maybe. Here is the code I have so far to display the products, but for some reason, it only show 1 row instead of all the rows from my table. Code: [Select] <?php $dbhost = "localhost"; $dbuser = "user"; $dbpass = "pass"; $dbname = "dbname"; mysql_connect ($dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $result = mysql_query("SELECT * FROM mcproducts"); while($row = mysql_fetch_array($result)) { $products_local_id = $row['products_local_id']; $productname = $row['product_name']; $thumburl = $row['image_from_url']; $productlink = $row['product_local_url']; $thumbnail = $row['product_image_small']; $currencysymbol = $row['product_currency']; $price = $row['product_price']; $flagicon = $row['product_country_from']; } ?> <html> <head> <link href="style/stylesheet.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="displaybox"> <div class="productimage"> <a href="<?php echo $productlink; ?><?php echo $products_local_id; ?>"><img src="<?php echo $thumburl; ?><?php echo $thumbnail ?>" width="150" height="150"></a> </div> <div class="productdescription"> <div class="pro_name"> <a href="<?php echo $productlink ?><?php echo $products_local_id; ?>"><?php echo $productname; ?></a> </div> <div class="pro_description"> </div> <?php if ($flagicon=="Ireland") { $flagicon = "<img src=\"flags/ireland.jpg\">"; } elseif ($flagicon=="UK") { $flagicon = "<img src=\"flags/uk.jpg\">"; } else echo ""; ?> <div class="pro_description"><?php echo $flagicon; ?><?php echo $currencysymbol ?> <?php echo $price ?></div> </div> </div> </body> </html> Many thanks, DB |