Jump to content

jaymc

Members
  • Posts

    1,521
  • Joined

  • Last visited

    Never

Everything posted by jaymc

  1. jaymc

    Syntax

    It is not a syntax error e.g. not enclosing the FROM field in backticks `` It is saying vni.FROM doesnt exist In other words it cant use it in the sub select query..
  2. jaymc

    Syntax

    I also tried INNER JOIN (SELECT count(*) unread FROM media_1.virtual_number_inbox WHERE userID = '1' AND `READ` = '0' AND `FROM` = `vni.FROM`) as unreadcount Still it can't ackowledge `vni.FROM` And yes from is a field in my table although with the back ticks it never causes a problem Any more ideas?
  3. jaymc

    Syntax

    Query: SELECT count(*) as count, vni.id, vni.FROM, unread, vni.message, vni.network, vni.READ, DATE_FORMAT(vni.DATE, '%b %e at %l:%i%p') DATE, vn.number FROM media_1.virtual_number_inbox vni INNER JOIN media_1.virtual_numbers vn ON vni.vnID = vn.id INNER JOIN (SELECT count(*) unread FROM media_1.virtual_number_inbox WHERE userID = '1' AND `READ` = '0' AND `FROM` = vni.FROM) as unreadcount WHERE vni.userID = '1' GROUP BY vni.FROM Error Line: INNER JOIN (SELECT count(*) unread FROM media_1.virtual_number_inbox WHERE userID = '1' AND `READ` = '0' AND `FROM` = vni.FROM) as unreadcount Reason: It wont allow me to use vni.FROM as it is unable to see it even though it is part of the rest of my query. How can I write this query to achieve what I want which is basically the result of the ERROR LINE included in the rest of my query result
  4. jaymc

    VPS Trial

    Does anyone know of a company that offers free trial of VPS (Virtual Private Server) Looking for min of 1 week trial with no obligation to buy Simply terminate if after the trial do not want to continue ?
  5. jaymc

    [SOLVED] SYNTAX

    Im a bit limited, this is for use with SMS, i receive a post which contains only a number in a table I have that number along with a clientID the clientID is actually part of the customers database name e.g. wecan_{clientID} = a customers database:- wecan_1 = customers database 1 wecan_2 = customers database 2 wecan_3 = customers database 3 wecan_4 = customers database 4 The problem is, the POST with the number does not contain the clientID therefor I cant join the customers DB without first knowing what the customers clientID is. I could do a query to first fetch this then run another query, but I am trying to put this all in one query..
  6. SELECT cvn.clientID FROM wecan.client_virtual_numbers cvn INER JOIN wecan_{I NEED THIS TO BE VALUE OF cvn.clientID}.table WHERE cvn.number = '145' WHERE I have {I NEED THIS TO BE VALUE OF cvn.clientID} that IS the name of the database e.g wecan_4 Can this be done? Something like this would be nice SELECT cvn.clientID FROM wecan.client_virtual_numbers cvn INER JOIN wecan_(SELECT clientID from wecan.client_virtual_numbers where number = '145').table WHERE cvn.number = '145'
  7. jaymc

    Index Help

    I have a query that is taking 2+ seconds to execute So, I really need to add some indexes to speed things up Attached is the query and the EXPLAIN Can anyone give any suggestions on fields I should index? explain SELECT ts.id, ts.originator, ts.mobile, ts.message, DATE_FORMAT(ts.date, '%b %e at %l:%i%p') date, ts.status, tc.name, tc.numTotalMessages, tc.numSentMessages, DATE_FORMAT(tc.date, '%b %e at %l:%i%p') date, tr.report FROM media_1.texts_sent ts INNER JOIN media_1.text_campaign tc ON ts.campaignID = tc.id LEFT JOIN( SELECT report, textID FROM media_1.texts_report ORDER BY date DESC ) AS tr ON ts.id = tr.textID WHERE ts.campaignID = '6' AND ts.userID = '1' GROUP BY ts.id ORDER BY ts.date DESC LIMIT 0,50 [attachment deleted by admin]
  8. Ok I came up with this $array['name'] = "Jamie"; $array['month'] = "January"; $string = "#name# how are you on #month# you good?"; preg_match_all('/#(.*?)#/', $string, $match); foreach ($match[1] as $data) { $string = str_replace("#$data#", $array[$data], $string); } echo $string; Anything better?
  9. The best thing I can do to explain what I want is to give you some sort of example. Look below <? $array['price'] = 415; $array['color'] = "red"; $array['computer'] = "linux"; $startString = "I have a #color# #computer# computer that cost me #price# pounds"; // What I want $endString = "I have a red linux computer that cost me 415 pounds"; ?> Points: The array key names could be anything e.g $array['sdfgdfhdasgadsfhg'] however if #sdfgdfhdasgadsfhg# is found it will replace #sdfgdfhdasgadsfhg# with what ever the value of $array['sdfgdfhdasgadsfhg'] So basically, find occurances of #*# where * could be anything. Check if the value in between #*# is a keyname of $array, if it is replace #*# with $array[*] So $array['food'] = "Pizza"; $string = "I love #food# I eat it all the time"; Becomes $string = "I love Pizza I eat it all the time"; Fire away!
  10. General question.. Im making a new website and at the moment I have error reporting set to display warnings for debugging. However, when for instance I do a foreach() : if the array is empty a warning error is displaed "invalid argument supplied for foreach()" Should I be checking if the array is empty before doing a foreach even if no harm can be done either way code side I turn warning errors off once I release live so even though they are there they will never cause any issues. It just seems very tedious to me to have if (!empty($array)) {foreach().......} any time I want to do a foreach on an array that may not contain any elements Your thoughts please? p.s - I know its good practice.. but seriously.. do you bother with the example given above?
  11. Ah I ended up making my own, I guess the best is one that works for you. Here it is // ########################################### // FUNCTION TO GENERATE DROP DOWN PAGE LINKS # // ########################################### function page_links($rowsPerPage, $totalRows, $currentRow, $url = false) { // ---------------------------------- // BUILD SELECT OPTION FOR EACH PAGE // ---------------------------------- if ($totalRows % $rowsPerPage == 0) {$offset = 0;} else {$offset = 1;} $pages = floor($totalRows / $rowsPerPage) + $offset; while ($i < $pages) { $i++; $page_from = ($i * $rowsPerPage) - $rowsPerPage; if ($page_from == $currentRow) {$selected = " SELECTED";} else {$selected = "";} $page_options .= "<option value=\"$page_from\"{$selected}>Page $i</option>"; } // ------------------------------- // REMOVE pageFrom= FROM QUERY STRING // ------------------------------- if (!$url) {$url = $_SERVER['QUERY_STRING'];} parse_str($url, $queryString); unset($queryString['rowFrom']); $urlQuery = rawurldecode(http_build_query($queryString)); // -------------------------------------- // PUT THE DROP DOWN TOGETHER AND RETURN // -------------------------------------- $page_jump = "<SELECT style=\"width:80px\" id=\"quick_jump_menu\" OnChange=\"ajaxopen('#center_content', '$_SERVER[sCRIPT_NAME]?$urlQuery&rowFrom=' + this.value)\">$page_options</SELECT>"; return $page_jump; }
  12. true, will have to edit a few things but would be a good start if someone has made a pretty generic function to handle it
  13. No its still to heavy, I just want a nifty piece of code to run as a simple function Something that I just pass $TotalNumRows, $RowsPerPage, $UrlqueryString
  14. I don't really want to use a framework just for this I'd prepare to just have it as a function file and include when I need it. I don't need the framework features.
  15. Does anyone have any nice prebuilt, re-useable functions that handle creating html numbed paged links to toggle between mysql result sets e.g mysql returns 500 rows, you split that up into 50 pages, 10 rows Im trying to avoid ugly code each time I need to do this, would be nice to have a reusable function that can handle returning the html paged links as well as maintain query strings I've seen a few on google but they arnt too great. Also the PHP_Pear is not to hot either How do you experts on here go about this
  16. That appears to work. Very small script too. Good work.
  17. Actually, sorry. That does not work Where I have used this dummy data for the example data1 data2 data3 data4 Those values can be anything, but you have based your code on them being hard set as data* Here is what the $_POST could come in as Array ( [fieldOne] => Array ( [row1] => cheese [row2] => red [row3] => rain ) [fieldTwo] => Array ( [row1] => beans [row2] => blue [row3] => snow ) ) Which I need converted to [0] => Array ( [fieldOne] => cheese [fieldTwo] => beans ) [1] => Array ( [fieldOne] => red [fieldTwo] => blue ) [2] => Array ( [fieldOne] => rain [fieldTwo] => snow ) So basically the [row1]'s must all be merged together in a new array, all the [row2]'s in another and so on... whilst using the original keyname of the array as each elements key name. The example above shows exactly what is needed
  18. Excellent! Worked first try Am I lacking in ability for spending 2 hours trying to do that? It really confused me, maybe I was looking at it the wrong way Thanks.
  19. An array comes in as this from a $_POST Array ( [fieldOne] => Array ( [row1] => data1 [row2] => data2 [row3] => data3 [row4] => data4 [row5] => data5 ) [fieldTwo] => Array ( [row1] => data1 [row2] => data2 [row3] => data3 [row4] => data4 [row5] => data5 ) [fieldThree] => Array ( [row1] => data1 [row2] => data2 [row3] => data3 [row4] => data4 [row5] => data5 ) [fieldFour] => Array ( [row1] => data1 [row2] => data2 [row3] => data3 [row4] => data4 [row5] => data5 ) ) I need to take row1, row2, row3, row4, row5 of each child array and push it into a new array using the keyname of the parent array as the keyname for each element in the new array The example below will show you the exact output I need [0] => Array ( [fieldOne] => data1 [fieldTwo] => data1 [fieldThree] => data1 [fieldFour] => data1 ) [1] => Array ( [fieldOne] => data2 [fieldTwo] => data2 [fieldThree] => data2 [fieldFour] => data2 ) [2] => Array ( [fieldOne] => data3 [fieldTwo] => data3 [fieldThree] => data3 [fieldFour] => data3 ) [3] => Array ( [fieldOne] => data4 [fieldTwo] => data4 [fieldThree] => data4 [fieldFour] => data4 ) [4] => Array ( [fieldOne] => data5 [fieldTwo] => data5 [fieldThree] => data5 [fieldFour] => data5 ) I dont think there is a function to do this, may requre some foreach stuff but Im getting no where Can anyone help?
  20. jaymc

    [SOLVED] ENUM

    I have an ENUM field of either 1, 0. However really I want to show 1 as Yes and 0 as No. How can I make it output it as Yes/No even though I store it as 1/0 This must be done in the query, no php str_replace etc.
  21. white-space: pre; Fixed the problem.
  22. I have a div with the following CSS properties .pop_menu { left:0; padding:5px; position:absolute; } My problem is, unless I specify a static width in the css the div does not expand to the length of the line text e.g This should be one line Becomes This should be one line
  23. jaymc

    GROUP BY ORDER

    Hmm yes, although trying your example with new fields,database It does not work Heres what I have got so far SELECT t.id, t.subject, t.department, tm.responder, tm.date FROM fred.client_tickets t INNER JOIN ( SELECT date, responder FROM fred.client_ticket_messages GROUP BY ticketID ) AS tm USING ( date, responder ) Error: Unknown column 'date' in from clause
×
×
  • 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.