Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. 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.
  2. 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
  3. Have you checked that the $info array contains what you expect?
  4. You create an intermediate table containing item_id | category_id one row for each cat/subcat the item belongs to
  5. :code_php_tags:
  6. you have no ; at the end of the statement on previous line
  7. 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
  8. Turn PHP error reporting on. You should be getting a syntax error with that code
  9. 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)
  10. Don't you already have that in your retailer table (id, user_id, prod_id)?
  11. 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>'; }
  12. Use the rows' primary keys to identify which x should get which value
  13. 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"];
  14. 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 | +------------------+ +--------------+
  15. And your question is ... ?
  16. you could look at http://datamarket.azure.com/dataset/bing/microsofttranslator https://developers.google.com/translate/
  17. pseudocode currentCategory = '' while (fetch row) { if (category != currentCategory) { output category currentCategory = category } output item, price }
  18. Barand

    Random

    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 */
  19. Why such a complex name for the select? Instead of <select name='valuta' ... > Then access it with $_POST['valuta']
  20. 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)
  21. 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
  22. 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
  23. Barand

    Random

    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
  24. You already have a current topic on this problem - http://forums.phpfreaks.com/topic/279246-help-with-my-form/ - don't double post.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.