Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. From that list it appears your xml records only contain (different) subsets of the whole record. You may have to break the rules and do a separate insert for each record. $xml = simplexml_load_file('feefofeedtest.xml'); $data = $fields = array(); foreach ($xml->xpath('FEEDBACK') as $FEEDBACK) { $fields = array_keys((array)($FEEDBACK)); $data = "('" . join("', '", (array)$FEEDBACK) . "')"; $sql = "INSERT IGNORE INTO feeforeviews (" . join(', ', $fields) . ") VALUES\n" ; $sql .= join (",\n", $data); if (!mysqli_query($con,$sql)) { echo "Error creating database: " . mysqli_error($con); } }
  2. Have you tried echoing the query string to check it is submitting what you think it's submitting? Have you checked $owner has a value? Have you checked if mysqli_error() returns a message?
  3. Can you post your table structure? SHOW CREATE TABLE freeforeviews
  4. I recommend you normalize your database correctly then come back when that is done
  5. . ^ my reply condensed to a single microdot
  6. this'll do it in a single query for you SELECT @serial:=@serial+1 as photo_number , photo_filename FROM ( SELECT photo_filename FROM gallery_photos JOIN (SELECT @serial:=0) as init ORDER BY RAND() LIMIT 20 ) as sorted
  7. Mea culpa. Should be escaping the the data anyway. Try this to escape each field foreach ($xml->xpath('FEEDBACK') as $FEEDBACK) { $fields = array_keys((array)($FEEDBACK)); $data[] = "('" . join("', '", array_map(array($con, real_escape_string), (array)$FEEDBACK)) . "')"; }
  8. You could do something like this mysql> SELECT * FROM test1; +----+--------------------+------+ | id | http_referrer | hit | +----+--------------------+------+ | 1 | www.google.com?abc | 3 | | 2 | www.google.com&def | 5 | | 3 | www.yahoo.com?xyz | 10 | | 4 | www.yahoo.com&tuv | 4 | +----+--------------------+------+ SELECT CASE WHEN LOCATE('?',http_referrer )>0 THEN SUBSTRING_INDEX(http_referrer, '?', 1) WHEN LOCATE('&', http_referrer)>0 THEN SUBSTRING_INDEX(http_referrer, '&', 1) ELSE http_referrer END as referrer , SUM(hit) as hits FROM test1 GROUP BY referrer +----------------+------+ | referrer | hits | +----------------+------+ | www.google.com | 8 | | www.yahoo.com | 14 | +----------------+------+
  9. String values in your query need to be enclosed in single quotes EG VALUES (..., '3 Hour(s) ago', '2014-03-18T10:19:03', 'Personalised Swarovski Crystal Hiball Glass', 'D', ... ) In the code you copied/pasted these quotes were already present in the XML data. They are not present in yours so you need to insert them when joining the values. So this line $data[] = '(' . join(', ', (array)$FEEDBACK) . ')'; needs to be $data[] = "('" . join("', '", (array)$FEEDBACK) . "')";
  10. The sample code just displays the query to demonstrate what it is doing. Are you actually executing the sql produced with mysqli_query()?
  11. MySQL Admin is fine for editing records. Open a connection under "SQL Development" Right click a table name and select "Edit table data"
  12. try like this SELECT SUBSTRING_INDEX(http_referrer, '?', 1) as referrer , SUM(hit) as hits FROM global_stats GROUP BY referrer
  13. try SELECT http_referrer, SUM(hit) as 'hits' FROM `global_stats` GROUP BY `http_referrer`
  14. Normalize your data correctly and problem goes away
  15. Both are certainly possible. How you do it would depend on your data, how you want to link the pages, the charting software you are planning to use. Your question is far to broad at the moment for a more detailed response but so long as you properly normalize the data in your db then you should be OK for most things.
  16. try something like this $datakeys = array('apple','orange','pear','banana'); $sql = "SELECT year, type, amount FROM mytable ORDER BY year"; $res = $mysqli->query($sql); $curryear = 0; $data = array(); while (list($year, $type, $amount) = $res->fetch_row()) { if ($year != $curryear) { $data[$year] = array_fill_keys($datakeys, 0); $curryear = $year; } $data[$year][$type] = $amount; }
  17. I'd order by year, type to get close value before the open value
  18. I'd create a second database containing the relevant table/s only and restore into those. Then run a query to select the desired information.
  19. echo gethostbyname($server_data['ip']); if($server_data['port'] != 1234){ echo ":" . $server_data['port']; }
  20. you need a left join between the tables and use IFNULL() to show the desired values
  21. have a look at the example in the manual http://uk1.php.net/manual/en/function.mysql-fetch-assoc.php
  22. Psycho, I was equally confused by his first topic on this problem.
  23. You can select and write to outout file all in a single query with SELECT...INTO OUTFILE http://dev.mysql.com/doc/refman/5.6/en/select-into.html
  24. I can see that the "driver_id" in the log would match with the "id" in the driver table but I am totally confused over the other matches. It sounds as though the referred_as columns should match but one is numeric in one table and alpha in the other. Ditto the "associated" columns.
×
×
  • 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.