-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Creating a dynamic table with 5 columns per row
Barand replied to Texan78's topic in PHP Coding Help
How are you planning on setting the different values for $alertColor each time you output a <span>? -
I see what you mean. I had a closer look at his array. I saw what I expected to see last time. $list = array( 'location', 'ID', 'section', $location, $ID, $section );
-
ginerjm, fputcsv($file,explode(',',$line),','); | | | FYI, that is a comma
-
Displaying multiple row stored data in a single <td>
Barand replied to surveen's topic in PHP Coding Help
Not in the sample you gave us. Perhaps if you gave us a more comprehensive illustration of of your current output problem and also an example of how you would want it to appear. -
Displaying multiple row stored data in a single <td>
Barand replied to surveen's topic in PHP Coding Help
If you don't want to repeat the supplier details then keep track of when the supplier changes and only output the details on that change. I have modified NotionCommotion's code to demonstrate. I also removed the superfluous columns that you were selecting but not using. if(isset($_POST['submit']) && ($_POST['vendor']!='') && ($_POST['item']!='')) { $sql="SELECT supplier.id AS sid , supplier.name AS SNAME , supplier.category , supplier.website , supplier.email , supplier.phone , supplier.vat , supplier.pan , location.name AS locname , products.name AS pname FROM supplier INNER JOIN supplier_location ON supplier.id = supplier_location.supplier_id INNER JOIN supplier_products ON supplier.id=supplier_products.supplier_id INNER JOIN location ON supplier_location.location = location.loc_id INNER JOIN products ON supplier_products.product_id=products.product_id WHERE supplier.id='$sup' AND supplier_products.product_id= '$product' ORDER BY sid"; $sql1 = mysql_query($sql) or die(mysql_error()); echo('<table> <thead> <tr> <th>Vendor ID</th> <th>Vendor</th> <th>Category</th> <th>Website</th> <th>Email</th> <th>Phone</th> <th>Products</th> <th>Locations</th> <th>VAT</th> <th>PAN</th> </tr> </thead> <tbody> '); $current = ''; // STORE THE SUPPLIER SID while($row = mysql_fetch_array($sql1)) { if ($row['sid'] != $current) { echo "<tr> <td>{$row['sid']}</td> <td>{$row['SNAME']}</td> <td>{$row['category']}</td> <td>{$row['website']}</td> <td>{$row['email']}</td> <td>{$row['phone']}</td>"; $current = $row['sid']; // RESET STORED SID } else { echo "<tr><td colspan='6'> </td>"; } echo "<td>{$row['pname']}</td> <td>{$row['locname']}</td> <td>{$row['vat']}</td> <td>{$row['pan']}</td> </tr>"; } echo('</tbody></table>'); } else{echo 'Nothing';} -
Multiple queries issue when included in another file.
Barand replied to SF23103's topic in PHP Coding Help
$chef is not defined in instructors.php. Global applies only to the page it is on (and is bad practice). Use a session variable if you want to preserve the value for use on another page. session_start(); ... $chef = $row['Instructor']; $_SESSION['chef'] = $chef ; then in instructor.php session_start(); ... $chef = $_SESSION['chef'];- 3 replies
-
- multiple queries
- mysqli
-
(and 1 more)
Tagged with:
-
If you are going to use printf(), use it correctly with %s placeholder for the string argument. printf('<p style="text-align: left; width: 500px;">%s</p>', htmlspecialchars($fetch['shout'], ENT_QUOTES, 'UTF-8'));
-
Try switching it to a select query to see which rows it thinks should be deleted and see if that gives any clues SELECT * FROM booking_slots INNER JOIN booking_reservation USING (slot_id) WHERE booking_slots.slot_date BETWEEN '2012-01-01' AND '2013-01-01'
-
$responsArray = array( .... echo json_encode ($responseArray);
-
Not sure what this Comparison Operators means
Barand replied to andreea120's topic in PHP Coding Help
did you try the PHP manual? http://php.net/manual/en/language.operators.comparison.php -
Your subquery should be finding the max version for the post_id, not the title. Unfortunately, given three solutions in that link, you opted for the first one which the manual clearly states is inefficient. Personally, I prefer the second option given. When you use an INNER JOIN between two table the query only returns rows where there is a match in both tables. So if you had a table that contained the post_id and the max version for the post_id you could match your table against it so you only see those with the latest version. You can create this second table, not as a physical table in your db but as a "logical" table, by using a table subquery. (SELECT post_id , MAX(version) as version FROM table GROUP BY post_id) as maxv Now join your table to the maxv table in your query matching on post_id and version SELECT id , postID , title , content , version FROM table t1 INNER JOIN ( SELECT post_id , MAX(version) as version FROM table GROUP BY post_id ) as maxv USING (post_id, version) WHERE title LIKE '%SOME_TITLE%'
-
Not tested. Backup data before trying. Assumes the dates are stored correctly in yyyy-mm-dd format (other formats will not work for range comparisons) DELETE booking_slots, booking_reservation FROM booking_slots INNER JOIN booking_reservation USING (slot_id) WHERE booking_slots.slot_date BETWEEN '2012-01-01' AND '2013-01-01'
-
Is it possible to do what? You haven't said what it is you you are trying to achieve, other than, whatever it is, you want to use a single query to do it.
-
Is it possible to allign each row (sql query) different
Barand replied to Klein_Kipje's topic in PHP Coding Help
The relevant bit is -
Is it possible to allign each row (sql query) different
Barand replied to Klein_Kipje's topic in PHP Coding Help
If you allocate 3x as many columns to your HTML table then you can arrange them by outputting empty cells. In this example there are 3 rooms, and the room number sets the left, centre or right position mysql> SELECT * FROM timetable; +--------------+-----------+------+----------+----------+ | timetable_id | subject | room | timefrom | timeto | +--------------+-----------+------+----------+----------+ | 1 | English | 1 | 09:00:00 | 10:00:00 | | 2 | Maths | 2 | 10:00:00 | 11:00:00 | | 3 | Biology | 3 | 11:00:00 | 12:00:00 | | 4 | Geography | 2 | 13:00:00 | 14:00:00 | | 5 | History | 3 | 14:00:00 | 15:00:00 | +--------------+-----------+------+----------+----------+ the sample code $mysqli = new mysqli(HOST,USERNAME,PASSWORD,'test'); $sql = "SELECT subject , room , timefrom , timeto FROM timetable ORDER BY timefrom"; $res = $mysqli->query($sql); $ttdata = ''; while (list($sub,$room,$from,$to) = $res->fetch_row()) { $from = date('g:i', strtotime($from)); $to = date('g:i', strtotime($to)); $ttdata .= '<tr>'; switch ($room) { case 1: $ttdata .= "<td>$sub</td><td>$from</td><td>$to</td><td colspan='6' class='empty'></td></tr>"; break; case 2: $ttdata .= "<td colspan='3' class='empty'></td><td>$sub</td><td>$from</td><td>$to</td><td colspan='3' class='empty'></td></tr>"; break; case 3: $ttdata .= "<td colspan='6' class='empty'></td><td>$sub</td><td>$from</td><td>$to</td></tr>"; break; } } ?> <html> <head> <title>Sample</title> <style type="text/css"> table {border-collapse: collapse;} th {background-color: blue; color: white;} td {padding: 2px 4px;} td.empty {background-color: #eee;} </style> </head> <body> <table border="1" cellspacing="3"> <tr><th colspan='3'>Room 1</th><th colspan='3'>Room 2</th><th colspan='3'>Room 3</th></tr> <?=$ttdata?> </table> </body> </html> Output -
echo $ban; post the results from that so we can see if the query looks right
-
Suppose we have mysql> select * from appointment; +---------------+----------+-----------+------------+-----------+----------+ | idappointment | idclient | idstylist | app_date | app_start | app_end | +---------------+----------+-----------+------------+-----------+----------+ | 1 | 1 | 1 | 2014-12-18 | 10:00:00 | 10:45:00 | | 3 | 2 | 1 | 2014-12-18 | 12:00:00 | 12:45:00 | | 4 | 3 | 2 | 2014-12-18 | 10:00:00 | 10:45:00 | | 5 | 4 | 1 | 2014-12-18 | 13:00:00 | 13:45:00 | | 6 | 5 | 2 | 2014-12-18 | 16:00:00 | 16:45:00 | +---------------+----------+-----------+------------+-----------+----------+ and client wants to book 2014-12-18 from 12:45 to 13:30 SELECT s.idstylist , s.name , COUNT(idappointment) as clashes FROM stylist s LEFT JOIN appointment a ON s.idstylist = a.idstylist AND app_date = '2014-12-18' AND app_start < '13:30' AND app_end > '12:45' GROUP BY idstylist; which gives this +-----------+------+---------+ | idstylist | name | clashes | +-----------+------+---------+ | 1 | John | 1 | | 2 | Jane | 0 | +-----------+------+---------+ showing that Jane is free for that booking
-
Which field (A) provides the values for the column headings? Which field (B) provides the values for the row headings? Which field © provides the values for the totals? You would need something like SELECT A, B, SUM(C) as C FROM ... GROUP BY A, B then a while() loop to process the results. Output a row of totals for B when A changes
-
This may help. New booking is from start to end. Existing bookings are from s to e new booking | | start end ------------------------------------------------------------------- | | s--------e | clashing | s----e | | s-----------e e > start s---------------e && | | s < end | | -------------------------------------------------------------------- | | s------------e | | OK | | s----------e OK | |
-
If you have a new booking (time_start to time_end) then any other bookings where (bookingend > time_start) && (bookingstart < time_end) will clash with the new one
-
That's because you fetch a row at the top of your script then ignore it. Remove $row_consulta = mysql_fetch_assoc($consulta);
-
IP2Location Database IPv6 conversion to IP Number Decimal
Barand replied to brentman's topic in MySQL Help
If you are working with ip6 then you need INET6_ATON() . This function requires MySQL 5.6+ -
1 ) fetch_assoc() is a mysqli_result method, so you need to use $row = $banres->fetch_assoc(); 2 ) Also, to access $row['active'] you need to select 'active' in your query. You only select the id. 3 ) Use a prepared query or escape the GET value - don't use it directly in your query
-
How about SELECT a.yr , a.tot as yr_tot , b.tot as prev_yr_tot , IF(a.tot>=b.tot, 'more','') as more , IF(a.tot< b.tot, 'less','') as less FROM ( SELECT YEAR(vrijeme) as yr , SUM(nabavna_cijena) as tot FROM kalkulacija_stavke GROUP BY YEAR(vrijeme) ) as a LEFT JOIN ( SELECT YEAR(vrijeme) as yr , SUM(nabavna_cijena) as tot FROM kalkulacija_stavke GROUP BY YEAR(vrijeme) ) as b ON a.yr = b.yr + 1;