-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Using MYSQL Left Join to Order by Results of a SubQuery
Barand replied to ShoeLace1291's topic in PHP Coding Help
time -
Correct syntax to use variable inside as argument of $_POST[ ]
Barand replied to wahidku's topic in PHP Coding Help
The correct way is <input type="radio" name="serial_number" value="<?php echo $serial_number ?>" /> If the radio has a variable name you have no idea which POST variable to process - it could be called anything. -
Using MYSQL Left Join to Order by Results of a SubQuery
Barand replied to ShoeLace1291's topic in PHP Coding Help
I'd make a couple of changes to that query. In the subquery, have IFNULL(MAX(m.date_posted), '0000-00-00') as lastPost and then order the whole query by ORDER BY MAX(t.date_posted, q.lastPost) so it sorts by the lastest message (if exist) or the thread date, whichever is latest -
Pulling datestamp into html email ? Help required
Barand replied to Dicko_md's topic in PHP Coding Help
Have you checked that the $info array contains what you expect? -
Ecommerce Website - Creating Categories For Items
Barand replied to BorysSokolov's topic in PHP Coding Help
You create an intermediate table containing item_id | category_id one row for each cat/subcat the item belongs to -
:code_php_tags:
-
you have no ; at the end of the statement on previous line
-
How to output an array into email messages containing concatenated data?
Barand replied to lb3000's topic in PHP Coding Help
In my code, $currOrg gets set on the line after the part you just posted. That code was tested prior to posting. output was Organisation: organization_w Email: email_w Titles: publication_w1, publication_w2, publication_w3 Ids: pubID_w1, pubID_w2, pubID_w3 -------------------------------------------------------------------------------- Organisation: organization_x Email: email_x Titles: publication_x1, publication_x2, publication_x3 Ids: pubID_x1, pubID_x2, pubID_x3 -------------------------------------------------------------------------------- Organisation: organization_y Email: email_y Titles: publication_y1, publication_y2 Ids: pubID_y1, pubID_y2 -------------------------------------------------------------------------------- Organisation: organization_z Email: email_z Titles: publication_z Ids: pubID_z -
Turn PHP error reporting on. You should be getting a syntax error with that code
-
You don't need, and shouldn't, reconnect before each query. It's usually the slowest part of the process. You only to connect once per page. I'd connect to the database then pass $db to the class constructor. Inside the function you then reference $this->db class foo { private $db; function __construct($db) { $this->db = $db; } function bar() { $result = $this->db->query("SELECT blah from table"); .... return $blah; } } $db = new mysqli(......); $obj = new foo($db)
-
Don't you already have that in your retailer table (id, user_id, prod_id)?
-
How to output an array into email messages containing concatenated data?
Barand replied to lb3000's topic in PHP Coding Help
try $arr = array ( array('org' => organization_w, 'email' => email_w, 'title' => publication_w1, 'pub_id' => pubID_w1), array('org' => organization_w, 'email' => email_w, 'title' => publication_w2, 'pub_id' => pubID_w2), array('org' => organization_w, 'email' => email_w, 'title' => publication_w3, 'pub_id' => pubID_w3), array('org' => organization_x, 'email' => email_x, 'title' => publication_x1, 'pub_id' => pubID_x1), array('org' => organization_x, 'email' => email_x, 'title' => publication_x2, 'pub_id' => pubID_x2), array('org' => organization_x, 'email' => email_x, 'title' => publication_x3, 'pub_id' => pubID_x3), array('org' => organization_y, 'email' => email_y, 'title' => publication_y1, 'pub_id' => pubID_y1), array('org' => organization_y, 'email' => email_y, 'title' => publication_y2, 'pub_id' => pubID_y2), array('org' => organization_z, 'email' => email_z, 'title' => publication_z, 'pub_id' => pubID_z) ); $currOrg = ''; foreach ($arr as $data) { if ($currOrg != $data['org']) { if ($currOrg) { outputEmail ($currOrg, $currEmail, $titles, $ids); } $currOrg = $data['org']; $currEmail = $data['email']; $titles = $ids = array(); } $titles[] = $data['title']; $ids[] = $data['pub_id']; } outputEmail ($currOrg, $currEmail, $titles, $ids); function outputEmail($org, $email, $titles, $ids) { // format your output here echo "Organisation: $org<br>"; echo "Email: $email<br>"; echo "Titles: " . join(', ', $titles) . '<br>'; echo "Ids: " . join(', ', $ids) . '<hr>'; } -
Use the rows' primary keys to identify which x should get which value
-
line 118 is missing ; at end of statement and you are using the wrong variable on line 121 $objResult = mysql_fetch_array($objQuery); $provinceFullName = $objResult["province_english"];
-
I can understand that retailers would have different prices but why would descriptions of the same product be different for each retailer? More likely the model would be more like this +------------+ +--------------+ | retailer | | product | +------------+ +--------------+ | user_id |----+ +------------------+ +-----| product_id | | user_name | | | retailer_product | | | prod_name | | etc | | +------------------+ | | prod_desc | +------------+ +---<| user_id | | | manufacturer | | product_id |>---+ | product_code | | price | | etc | +------------------+ +--------------+
-
And your question is ... ?
- 4 replies
-
- calculator
- php
-
(and 1 more)
Tagged with:
-
you could look at http://datamarket.azure.com/dataset/bing/microsofttranslator https://developers.google.com/translate/
-
pseudocode currentCategory = '' while (fetch row) { if (category != currentCategory) { output category currentCategory = category } output item, price }
-
Not sure how they are related or what you mean at all but this would be a more general solution using MySql and PHP $chosen_topics = '1,3'; $q_per_topic = 2; $sql="SELECT topic_id, qid FROM questions WHERE topic_id IN ($chosen_topics)"; $qs = $chosen = array(); $res = $db->query($sql); while (list($tid,$qid) = $res->fetch_row()) { $qs[$tid][] = $qid; } foreach ($qs as $tid=>$qarray) { $selects = array_rand($qarray, $q_per_topic); foreach ($selects as $s) { $chosen[$tid][] = $qarray[$s]; } } foreach ($chosen as $tid => $qselected) { printf ("Topic %s : Questions %s<br>", $tid, join(', ', $qselected)); } /*** OUTPUT ******************** Topic 1 : Questions 2, 3 Topic 3 : Questions 7, 8 */
-
Why such a complex name for the select? Instead of <select name='valuta' ... > Then access it with $_POST['valuta']
-
If you had normalized your data instead of storing the type descriptions in every record you would have had a table of type descriptions with ids. IF you had this table you could LEFT JOIN to your data table ensuring all types were present even if there was no data for a type (ie your zero totals)
-
Storing arrays - each value should be in a row of its own with an id link to a parent table INSERT INTO tablename (col) VALUES ('val1, val2, val3') WRONG INSERT INTO tablename (col1, col2, col3) (val1, val2, val3) WRONG INSERT INTO tablename (id, col) VALUES (id,val1),(id,val2),(id,val3) RIGHT
-
you should not run queries inside loops, it kills performance. The efficient solution was the one I gave you above http://forums.phpfreaks.com/topic/279279-output-sql-query-into-variable/?do=findComment&comment=1436579
-
Selecting two random questions from three is the same as omitting a random question. Use a subquery to select a randon question from each group the use a left join to omit the matching question. SELECT q.topic_id, q.qid FROM questions q LEFT JOIN ( SELECT topic_id, FLOOR(MIN(qid) + RAND()*(MAX(qid)-MIN(qid))) as qid FROM questions GROUP BY topic_id ) as random USING (topic_id, qid) WHERE random.qid IS NULL
-
You already have a current topic on this problem - http://forums.phpfreaks.com/topic/279246-help-with-my-form/ - don't double post.