PHP - Populate Table Column Based On Timestamp
Dear All
I want to display my data in tabular columns with the headings of table like 00:06-00:08,00:08-00:10,00:10:00:12:00........22:00-24:00.i.e.time In database I have two columns one containing value and other containing time when this reading was done. I could retrieve data from my mysql table in php and look at time. I want to know how could I insert the value to the correct column of table based on the time. e.g If I have record in table in database say containing value 09:45 and 5. I want this value to go to the column heading 00:08-00:10 and same thing for the other values. I hope I am clear with the problem definition but if you need more info.Please let me know. Thanks, elp Similar TutorialsI'm wondering how to do this with javascript for a table that i have made in php and html. I want to hide the row for the table based on the value inside my first column for each row of the table. Like if column 1 has "apple" inside it, then the row would not be shown. I'm pretty sure this can be done in javascript but i'm not a coding guy, so any help would be appreciated! My table.php file that has the table i want to do this for: Code: [Select] <script language="javascript"> imageX1='plus'; imageX2='plus'; imageX3='plus'; function toggleDisplay(e){ imgX="imagePM"+e; tableX="table"+e; imageX="imageX"+e; tableLink="tableHref"+e; imageXval=eval("imageX"+e); element = document.getElementById(tableX).style; if (element.display=='none') {element.display='block';} else {element.display='none';} if (imageXval=='plus') {document.getElementById(imgX).src='http://www.pvpstreams.com/icons/wowicon.png';eval("imageX"+e+"='minus';");document.getElementById(tableLink).title='Hide WoW';} else {document.getElementById(imgX).src='http://www.pvpstreams.com/icons/wowicon.png';eval("imageX"+e+"='plus';");document.getElementById(tableLink).title='Show WoW';} } </script> <?php $username="user"; $password="password"; $tmp="database"; mysql_connect(localhost,$username,$password); @mysql_select_db($tmp) or die( "Unable to select database"); $query="SELECT * FROM users"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table class="sortable" id="wow" border="1" cellpadding="0" cellspacing="0" style="margin-left:auto;margin-right:auto;text-align:left"> <tr> <th><font face="Arial, Helvetica, sans-serif">Game</font></th> <th><font face="Arial, Helvetica, sans-serif">Character</font></th> <th><font face="Arial, Helvetica, sans-serif">Rating</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/xfirelogo.png"> Status</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/xfirelogo.png"> Link</font></th> <th><font face="Arial, Helvetica, sans-serif">Realm</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/livestreamlogo.png"> Status</font></th> <th><font face="Arial, Helvetica, sans-serif"><img src="http://www.pvpstreams.com/table-images/livestreamlogo.png"> Link</font></th> <th><font face="Arial, Helvetica, sans-serif">Team Setup</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"wowcharacter"); $f2=mysql_result($result,$i,"username"); $f3=mysql_result($result,$i,"livestream"); $f4=mysql_result($result,$i,"wowserver"); $f5=mysql_result($result,$i,"wowplayer1"); $f6=mysql_result($result,$i,"wowplayer2"); $f9=mysql_result($result,$i,"wowplayer3"); $f7=mysql_result($result,$i,"wowrealm"); $f8=mysql_result($result,$i,"xfire"); $f10=mysql_result($result,$i,"xfirecheck"); $f11=mysql_result($result,$i,"wowrating"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<center><img src=http://www.pvpstreams.com/table-images/wowtable.png>"; ?></center></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://$f4.battle.net/wow/en/character/$f7/$f1/simple>$f1</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f11; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "$f10"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://www.pvpstreams.com/xfire.php?user=$f2>$f8</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f7; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php include("livestreamcheck.php"); ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<a class=blue href=http://www.pvpstreams.com/livestream.php?user=$f2>$f3</a>"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo "<img src=http://www.pvpstreams.com/wclassicons/$f5.png><img src=http://www.pvpstreams.com/wclassicons/$f6.png><img src=http://www.pvpstreams.com/wclassicons/$f9.png>" ?></font></td> </tr> <?php $i++; } ?> </table> Hi all,
How can i auto populate the price of an item based on a chosen product and then auto calculate the price and quantity before hitting the ADD button. The Unit price should be auto populated based on valu from the database. The amount is the Unit Price times the Quantity of the Product Selected. Thanks My form <form action="" method="post" data-toggle="validator"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Item Name</label> <select id="username" name="item_name" class="form-control inputs" data-error="Select Item" required> <option value="">Chose Item</option> <?php $stmt = $pdo->query(" SELECT item_name FROM stocks ORDER BY item_name ASC "); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $item_name = $row['item_name']; echo "<option value=\"$item_name\"> $item_name </option>"; } ?> </select> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-2"> <div class="form-group"> <label>Unit Price</label> <input type="number" class="form-control" name="item_price"> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-2"> <div class="form-group"> <label>Item Quantity</label> <input type="number" class="form-control" name="item_qty" required data-error="Stock Quantity is missing"> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-2"> <div class="form-group"> <label>Amount</label> <input type="number" class="form-control" name="amount" > <div class="help-block with-errors"></div> </div> </div> </div> <br> <span class="input-group-btn"> <input name="send" type="submit" class="btn btn-danger btn-form display-4 rounded" value="ADD"> </span> </form>Edited May 4, 2019 by I-AM-OBODO Hey Guys I have the following table: (login) I need that table to be echoed he But it needs to filter it for the school they are logged in as. Help: When they login they have to select what school they are at so you can use that code. example: PHS = Poole High School I have a table that allows users to add rows, depending on how much data they need to insert. upon submit I'd like to populate another table for review. Now I can generate the data, but I'm having trouble putting the array into a table. Here is the output from the initial page: Code: [Select] Array ( [quantity] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [description] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [unit_cost] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [shipping] => 4 [tax] => 5 [review_po] => Review ) I need it to look like this: Quantity | Description | Unit Cost 1 | 1 | 1 2 | 2 | 2 3 | 3 | 3 Tax | 4 Ship | 5 I think it's a foreach statement, but I'm not having any luck.. If someone could point me in the right direction??? Hi guys, PHP advanced amateur and PHPFreaks newbie here. I have a problem with some code I've written. What the code is supposed to do, is take in 15 records in a single MySQL table column, and then print them out in a format like this: 1 2 3 4 5 6 7 8 9 so on so on. Here is the page in question: http://robbieduggan.com/strawberry-interactive/portfolio-web-design.php Now the problem is, you can see 14 images there, but it seems to be negating the first one. Its always whatever row 0 is, because if I change the SORT BY attrabute in the code below, it's a different one that is missing. Here is my code to get the data: mysql_select_db($database_strawberry, $strawberry); $query_rsProjects = "SELECT page_unique_identity, clean_title, thumbnail FROM tblprojects ORDER BY `timestamp` DESC"; $rsProjects = mysql_query($query_rsProjects, $strawberry) or die(mysql_error()); $row_rsProjects = mysql_fetch_assoc($rsProjects); $totalRows_rsProjects = mysql_num_rows($rsProjects); And here is the code to create the table: echo "<table width='100%' border='0' cellspacing='5' cellpadding='5'>"; for($i = 0; $i < $totalRows_rsProjects; $i++) { $row = mysql_fetch_array($rsProjects); if($i % $columns == 0) { echo "<tr>"; } echo "<td>"; if($row['page_unique_identity'] != NULL){ echo "<a href='website-details.php?project=".$row['page_unique_identity']."'><img src='portfolio/".$row['thumbnail']."' alt=".$row['clean_title']." width='267' height='162' /></a>"; } echo "</td>"; if(($i % $columns) == ($columns - 1) || ($i + 1) == $totalRows_rsProjects) { echo "</tr>"; } } Thanks in advance for any help Hi I have members DOB stored in a mysql table field called birthday in the following format YYYY-MM-DD I can't seem to convert the time stamp into the members age I need to be able to feed $birthday which is the field in mysql table that is in the above format and then use php code to convert to members age Everything I try doesn't seem to work Hello everyone! I am trying to insert a student into a table (with TIMESTAMP; works with VARCHAR, not TIMESTAMP). Can anyone help?
Variable
$time_stamp = date("D M j G:i:s T Y");Populate DB Query ("DROP TABLE IF EXISTS enrolled") || !$link->query("CREATE TABLE enrolled(course_id VARCHAR(50), student_id VARCHAR(50), user_ip VARCHAR(50), time_stamp TIMESTAMP(6))Insert Query INSERT INTO enrolled(course_id,student_id,user_ip,time_stamp) VALUES('$course','$number','$user_ip','$time_stamp') Edited by MatthewPatten, 12 December 2014 - 08:32 AM. I have a simple mysql database holding information about an image upload including its 'name' and 'date uploaded' [current_timestamp()] to a folder 'image' I then display it into a table using the php ‘foreach’ facility. I want the date to be displayed in the ‘dd/mm/yyyy’ format. not the default yyyy/mm/dd. Here is the relevant code <?php $conn = mysqli_connect("localhost", "root", "", "dbname"); $results = mysqli_query($conn, "SELECT * FROM tablename"); $image = mysqli_fetch_all($results, MYSQLI_ASSOC); ?> <?php foreach ($image as $user): ?> <td><p>NAME</p><?php echo $user['name']; ?></td> <td><p>COMMENT</p><?php echo $user['comment']; ?></td> <td><p>DATE</p><?php echo $user['date']; ?></td> What do I need to do? THANKS- Warren Hi Good day Can someone pls help me regarding with this matter. I have a page for inserting records. And I have a combobox that is fetched through the specific field in database. I also have a table of records, for each row i have an href edit which throws the values to its respective texbox and combobox. THE PROBLEM is that when i click the href edit, the value from a selected row was not displayed from the combobox To accomplish the layout I was looking for, I used the following code: for ($i=1; $i<=7; $i++) { //set day of week for display as title of columns $dow=date("l", strtotime($year.'W'."$weekno"."$i")); echo "<td class=\"wvcolumn\" valign=\"top\"> <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\" width=\"$daycolumn\"> <tr><th class=\"wvtitle\" valign=\"bottom\" align=\"center\" width=\"$daycolumn\"><a class=\"titledate\" href=\"createticket.php?action=o&month=".date("m", strtotime($year.'W'."$weekno"."$i"))."&date=".date("d", strtotime($year.'W'."$weekno"."$i"))."&year=".date("Y", strtotime($year.'W'."$weekno"."$i"))."\">$dow, ".date("F d", strtotime($year.'W'.$weekno."$i"))."</a> <a onClick=\"window.open('http://www.batchgeo.com')\" title=\"Map $dow's Appointments\" href=\"mapday.php?week=$weekno&year=$year&day=$i\"><img width=\"20\" style=\"border-style: none\" src=\"../images/icon_globe.png\"></a></th></tr>"; if(date("Y-m-d")==date("Y-m-d", strtotime($year.'W'."$weekno"."$i"))) { $query = "SELECT fieldtickets.ticketnumber, fieldtickets.business, title, apptdatetime, DATE_FORMAT(apptdatetime,'%h:%i %p') AS fapptdatetime, status, billstatus, type, assigntech, clients.business FROM fieldtickets LEFT JOIN clients ON fieldtickets.business = clients.id WHERE status='Open' AND (type = 'Field' OR type = 'Phone') AND apptdatetime BETWEEN '".date("Y-m-d", strtotime($year.'W'."$weekno"."$i"))." 00:00:00' AND '".date("Y-m-d", strtotime($year.'W'."$weekno"."$i"))." 23:59:59' UNION SELECT fieldtickets.ticketnumber, fieldtickets.business, title, apptdatetime, DATE_FORMAT(apptdatetime,'%h:%i %p') AS fapptdatetime, status, billstatus, type, assigntech, clients.business FROM fieldtickets LEFT JOIN clients ON fieldtickets.business = clients.id WHERE status = 'Pending' ORDER BY status ASC, apptdatetime ASC"; } else { $query = "SELECT fieldtickets.ticketnumber, fieldtickets.business, title, apptdatetime, DATE_FORMAT(apptdatetime,'%h:%i %p') AS fapptdatetime, status, billstatus, type, assigntech, clients.business FROM fieldtickets LEFT JOIN clients ON fieldtickets.business = clients.id WHERE status='Open' AND (type = 'Field' OR type = 'Phone') AND apptdatetime BETWEEN '".date("Y-m-d", strtotime($year.'W'.$weekno."$i"))." 00:00:00' AND '".date("Y-m-d", strtotime($year.'W'.$weekno."$i"))." 23:59:59' ORDER BY apptdatetime ASC"; } $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ //if ticket is open show appt time and business, if ticket pending display DELIVERY and business name if($row[status]=="Open") { $href="createticket.php?action=e&ticket=".$row[ticketnumber]; $time=$row[fapptdatetime]; $delivery=""; } elseif($row[status]=="Pending") { $href="createticket.php?action=c&ticket=".$row['ticketnumber'].""; $time=""; $delivery="DELIVER"; } echo "<tr><td valign=\"top\"><a title=\"".$row[ticketnumber]." - ".$row[title]."\" class=\"".$row[status]."\" href=\"$href\"><span>$delivery$time ".substr($row['business'], 0, $displaychars)."</span></a></td></tr>\n"; } echo "</table>"; } echo "</td></tr> </table>"; Output is similar to this, and any existing "deliveries" are displayed under the current day. _________________________________________________ ______________ | Monday | Tuesday | Wednesday | Thursday | Friday | |appointments |appointments |appointments |appointments |appointments This works great, but requires 5 separate queries. My database is very small for now, so its not a big deal, but I know this can be done much more efficiently. How can I query the whole week and put appointments in their corresponding tables (days)? Thank you for your help! Hi
I am very new to PHP & Mysql.
I am trying to insert values into two tables at the same time. One table will insert a single row and the other table will insert multiple records based on user insertion.
Everything is working well, but in my second table, 1st Table ID simply insert one time and rest of the values are inserting from 2nd table itself.
Now I want to insert the first table's ID Field value (auto-incrementing) to a specific column in the second table (only all last inserted rows).
Ripon.
Below is my Code:
<?php $con = mysql_connect("localhost","root","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ccc", $con); $PI_No = $_POST['PI_No']; $PO_No = $_POST['PO_No']; $qry = "INSERT INTO wm_order_entry ( Order_No, PI_No, PO_No) VALUES( NULL, '$PI_No', '$PO_No')"; $result = @mysql_query($qry); $val1=$_POST['Size']; $val2=$_POST['Style']; $val3=$_POST['Colour']; $val4=$_POST['Season_Code']; $val5=$_POST['Dept']; $val6=$_POST['Sub_Item']; $val7=$_POST['Item_Desc']; $val8=$_POST['UPC']; $val9=$_POST['Qty']; $N = count($val1); for($i=0; $i < $N; $i++) { $profile_query = "INSERT INTO order_entry(Size, Style, Colour, Season_Code, Dept, Sub_Item, Item_Desc, UPC, Qty, Order_No ) VALUES( '$val1[$i]','$val2[$i]','$val3[$i]','$val4[$i]','$val5[$i]','$val6[$i]','$val7[$i]','$val8[$i]','$val9[$i]',LAST_INSERT_ID())"; $t_query=mysql_query($profile_query); } header("location: WMView.php"); mysql_close($con); ?>Output is attached. Hi All ,
I have a small table with 4 fields namely Day_ID, Dues, Last_Visit, Points. where Day_ID is an auto-increment field. The table would be as follows:
Day_ID -- Dues --- Last_Visit --- Points.
1 --------- 900 -------- 1/12 -------- 6
2 --------- 700 -------- 4/12 -------- 7
3 --------- 600 -------- 7/12 -------- 5
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
So this is the record of a person's visit to say a club. The last row indicates the last date of his visit to the club. His points on this date are 6. Based on this point value of 6 in the last row I want to retrieve all the previous BUT adjoining all records that have the same Points i.e. 6.
So my query should retrieve for me, based on the column value of Points of the last row (i.e. Day_ID - 6 ), as follows:
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
This problem stated above had been completely resolved, thanks to a lot of help from Guru Barand by this following query :-
$query = "SELECT cv.day_id, cv.dues, cv.last_visit, cv.points FROM clubvisit cv WHERE last_visit >= ( SELECT MAX(last_visit) FROM clubvisit WHERE points <> ( SELECT points as lastpoints FROM clubvisit JOIN ( SELECT MAX(last_visit) as last_visit FROM clubvisit ) as latest USING (last_visit) ) )";I am using this and it works perfectly except that now there is a slight change in the table because the criteria for points is now dependent on more than one column cv.points and is more like cv.points1, cv.points2, cv.points3 etc. So now I need to make a selection based on each of these cv.points columns. As of now I can still get the results by running the query multiple times for each of the cv.points columns ( seperately for cv.points1, cv.points2, cv.points3) and it works correctly. However I am wondering if there is a better way to do this in just one go. This not only makes the code repetitive but also since the queries are interconnected, involves the use of transactions which I wish to avoid if possible. The values that I require for each of the cv.point columns is 1. day_id of the previous / old day on which the cv.points value changed from the current day value, and 2. cv.points on that old/ previous day. So for example if the table is as below: Day_ID -- Dues --- Last_Visit --- Points1 --- Points2. 1 --------- 900 -------- 1/12 ----------- 9 ------------ 5 2 --------- 600 -------- 4/12 ----------- 6 ------------ 6 3 --------- 400 -------- 7/12 ----------- 4 ------------ 7 4 --------- 500 -------- 9/12 ----------- 5 ------------ 8 5 --------- 600 -------- 10/12 ---------- 6 ------------ 8 6 --------- 600 -------- 11/12 ---------- 6 ------------ 8 7 --------- 600 -------- 13/12 ---------- 6 ------------ 7 8 --------- 500 -------- 15/12 ---------- 5 ------------ 7 9 --------- 500 -------- 19/12 ---------- 5 ------------ 7 Then I need the following set of values : 1. day_id1 -- Day 7, points1 ---- 6, days_diff1 -- (9-7 = 2) . // Difference between the latest day and day_id1 2. day_id2 -- Day 6, points2 ---- 8, days_diff2 -- (9-6 = 3) 3. day_id3 -- .... and so on for other points. Thanks all ! Simple question but I couldn't find any straight forward answers.
I have a customer details table with: customer ID, name, address, email.
I also have an delivery table with delivery ID, customer ID, order ID.
How can I link the customer ID column from the customer table to the delivery table so that when changes occur on the customer table they subsequently alter all other tables?
I know it might use foreign keys but I couldn't find any online resource that explained how to use them properly.
Cheers
This is a little confusing so please bear with me. I was thinking of using left.join but couldn't figure out how to implement it properly. I am trying to order all of the results from a table names 'clans' based on how many points the clan has. To calculate the points you have to go into another table 'clanteams' and then loop every team in the clan pulling wins and losses from a row in a specific ladder table. Here is the code i have to calculate the points. Code: [Select] $total[wins] = 0; $total[loss] = 0; $members=mysql_query("SELECT id,clanid,teamid,DATE_FORMAT(datejoined,'%M %d, %Y') FROM clanteams WHERE clanid='$member[id]'"); while(list($id,$clanid,$teamid,$joined)=mysql_fetch_row($members)){ $team=mysql_query("SELECT name,ladderid FROM teams WHERE id='$teamid'"); if(mysql_num_rows($team) == 0) continue; $team=mysql_fetch_array($team); $ladder=mysql_query("SELECT name FROM ladders WHERE id='$team[ladderid]'"); $ladder=mysql_fetch_array($ladder); $linfo=mysql_query("SELECT rank,wins,loss FROM ladder_$team[ladderid] WHERE teamid='$teamid'"); $linfo=mysql_fetch_array($linfo); $total[wins] = $total[wins] + $linfo[wins]; $total[loss] = $total[loss] + $linfo[loss]; } $totalpoints = ($total[wins] * 2) - $total[loss]; So now i want to loop through every row in the clans table, and using the above code oder them by $total points. Ive spent hours wrapping my head around it and still cannot figure it out. Please help.
Hello,
I have a table like this: CREATE TABLE days ( id INT AUTO_INCREMENT, daya INT, dayb INT, PRIMARY KEY (id) ); INSERT INTO days VALUES (70, 19, 18), (69, 20, 17), (68, 24, 25), (67, 19, 18), (66, 19, 17), (65, 17, 16);
$sql = "SELECT d1.id AS id1, d2.id AS id2, IF((d1.daya-d2.daya)=1,1,0) + IF((d1.daya-d2.dayb)=1,1,0) + IF((d1.dayb-d2.daya)=1,1,0) + IF((d1.dayb-d2.dayb)=1,1,0) AS tcount FROM days AS d1 , days AS d2 WHERE d1.id IS NOT NULL AND d2.id IS NOT NULL AND d1.id > d2.id"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "<tr><td>" . $row["id1"] . "</td><td>". $row["id2"] . "</td><td>" . $row["tcount"]. "</td></tr>"; } echo "</table>";
Id1 Id2 Count 50 49 1 50 48 0 49 48 0 50 47 1 49 47 1 48 47 0 50 46 1 49 46 1 48 46 0 47 46 1 50 45 1 49 45 1 48 45 0 47 45 1 46 45 1 I need to convert the table into this form: id1 goes down the first column, and id2 is in the first row. How can i do this, please? can you give me some help? thank you! id2 49 48 47 46 45 id1 50 1 0 1 1 1 49 0 1 1 1 48 0 0 0 47 1 1 46 1 45
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 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. I have a table and one column has links that point to index.php?id= but I want it to display the info of that row of my database. On the index.php page i have this code Code: [Select] <?php include "dbaptsConfig.php"; // test id, you need to replace this with whatever id you want the result from $id = "1"; // what you want to ask the db $query = "SELECT * FROM `apartments` WHERE `id` = ".$id; // actually asking the db $res = mysql_query($query, $ms); // recieving the answer from the db (you can only use this line if there is always only one result, otherwise will give error) $result = mysql_fetch_assoc($res); // if you uncomment the next line it prints out the whole result as an array (prints out the image as weird characters) // print_r($result); // print out specific information (not the whole array) echo "id: ".$result['id']."<br />"; echo "username: ".$result['username']."<br />"; echo "type: ".$result['type']."<br />"; echo "title: ".$result['title']."<br />"; echo "description: ".$result['description']."<br />"; echo "county: ".$result['county']."<br />"; echo "town: ".$result['town']."<br />"; echo "phone: ".$result['phone']."<br />"; echo "rooms: ".$result['rooms']."<br />"; echo "bath: ".$result['bath']."<br />"; echo "squa ".$result['square']."<br />"; echo "rent: ".$result['rent']."<br />"; echo "time: ".$result['time']."<br />"; ?>I know there is something wrong with this cause I always get the same info no matter which apartment I click. Do I use the $_GET function and how do I implement this? I have an existing two table structure where sub-data is related to main data in a many-to-one relationship.
There are several identically named columns in both tables.
(The PHP database class will return an associative array that did not deal with identical keys in the row.)
I'm LEFT JOINing the sub-data to the main-data tables.
When using a stand-alone query browser (to experiment), the display shows all columns, even those column names that appear more than once in the row.
Is there a general approach to making keys (column names) unique strictly using a MySQL SELECT statement?
Perhaps using table aliases, how can I concat the alias to the columns that come from each table?
What I am trying to avoid is giving an alias to each column in a list of column names, such as:
SELECT
C.name AS C_name
C.numb AS C_numb
D.name AS D_name
D.numb AS D_numb
etc.
I am wanting more like the result one could guess would be from:
C.* AS C_*
D.* AS D_*
Or better:
* AS CONCAT(__TABLE__, '_', *)
if __TABLE was a magic constant (like PHP's __LINE__, __FILE__, etc).
Hi, Stuck again with the Joomla/K2 coding. Trying to output this field in a 2 column table but failing badly. Any help or ideas would be greatly appreciated. <?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <?php if($extraField->value): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <?php if ($extraField->name =='Closing date') : ?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemDateCreated"><?php echo JHTML::_('date', $this->item->publish_down ); ?></span> <?php else :?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php endif; ?> </li> <?php endif; ?> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> |