Jump to content

TEENFRONT

Members
  • Posts

    338
  • Joined

  • Last visited

    Never

Posts posted by TEENFRONT

  1. strangely, also an example from the net returns empty aswell.

     

    $xml = '
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <cars>
    <make name="Ford">
    	<model>Mustang</model>
    </make>
    <make name="Honda">
    	<model>Accord</model>
    </make>
    </cars>
    ';
    $xml = simplexml_load_string($xml);
    echo $xml->make[0]['name'];
    

     

    that doesnt work either, just outputs nothing.

  2. Hey,

     

    Having some troubles extracting data from simpleXML object.

     

    var_dump outputs all the stuff correctly but when i try access data in the object, it just comes back empty.

     

    $rss = "/data/rss/";
    $rss = file_get_contents($rss); // simplexml_load_file() fails
    $feed = new SimpleXMLElement($rss);
    
    foreach($feed->item as $news) {
    echo $news->title; // returns empty
    }
    
    echo $feed->item->title; // also is empty
    

     

    so var_dump($feed) outputs this, shortened version:

     

    object(SimpleXMLElement)#10 (2) { ["@attributes"]=> array(1) { ["version"]=> string(3) "2.0" } ["channel"]=> object(SimpleXMLElement)#11 (6) { ["title"]=> string(38) "Bradford Bulls Super League Rugby News" ["description"]=> string(75) "RSS Feed for the latest Bradford Bulls Super League rugby news and updates." ["link"]=> string(46) "http://www.superleaguefans.com/bradford-bulls/" ["language"]=> string(2) "en" ["pubDate"]=> string(26) "Sat, 03 Sep 13:42:39 +0100" ["item"]=> array(10){ [0]=> object(SimpleXMLElement)#12 (1) { ["title"]=> string(32) "Briggs and Walker in Bulls squad" } } } } 
    

     

    so, $feed->item->title  should return the ["title"] contents, but it doesn't, driving me crazy.

     

    what am i doing wrong? Any pointers will be much appreciated, thank you.

  3. Hi,

     

    Cut down code

    SELECT count(number) FROM table GROUP BY title
    
    echo $title .'<br>'. $number;
    
    

     

    That outputs

     

    Title1
    5
    
    Title2
    9
    
    Title3
    2
    

     

    But what do i do if i wanted to retain and loop through the "$number" actual values, not JUST count the total? I still need access to what "$number" is while looping. But as GROUP BY returns one result.. im stuck.

     

    Ideally i want this as the resulting output

     

    title1 // grouped title
    3   // total number of $numbers per grouped title
    1234
    12345
    123456  // The actual values of $number totalling to the above grouped number
    
    title2 // grouped title
    2   // total number of $numbers
    1234
    123456  // The actual values of $number totalling to the above grouped number
    

  4. Hi,

     

    Iv just changed it slightly as i now need to count the amount of INCIDENT_NO's per SCHEME_CODE. Iv got this..

     

    $sql = "SELECT INCIDENT_NO, SCHEME_CODE FROM incidents WHERE JOB_DATE_TIME LIKE '$searchDate' AND SCHEME_CODE != '' ORDER BY SCHEME_CODE, INCIDENT_NO ASC";
    $query = mysql_query($sql) or trigger_error('MySQL Error: ' . mysql_error());
    
    $prev_code = '';
    $num = '';
    
    while ($row = mysql_fetch_assoc($query))
    {
        if ($prev_code != $row['SCHEME_CODE'])
        {
            $prev_code = $row['SCHEME_CODE'];
            echo $num; 
            $num =''; 
            echo '<br />' . $prev_code . '<br />';
        }
    
        $num++; 
    
    }
    
    }
    

     

    that outputs

     

    ALLASS
    5
    CTLR
    83
    DHOL1
    174
    FMNI
    37
    FR
    104
    HEX
    173
    JMR
    4
    RANS
    14
    ROLR
    2
    SCAS
    2
    SDC
    58
    TE1
    

     

    As you can see the last one TE1 is missing its count. I know why - its because the code is set to count the previous SCHEME_CODE then on outputting the new SCHEME_CODE, show the number of incidents, and the last one, doesnt have one after to show.

     

    Any advice? Or another way to count each incidents per title?

     

    The output looks like this (cut down) without the adding of  incident amounts.

     

    ALLASS
    1
    2
    3
    4
    CTLR
    1
    2
    3
    4
    

     

    So what im doing is counting the amount of "numbers" (INCIDENT_NO's) per title (SCHEME_CODE) .. and running into an issue with the last one.

     

  5. Sure i simply have a select like auggested above..

     

    $query = "SELECT INCIDENT_NO, SCHEME_CODE FROM incidents WHERE JOB_DATE_TIME LIKE '$searchDate' ORDER BY SCHEME_CODE, INCIDENT_NO ASC";
    
    $sql = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($sql)){
    echo $row['SCHEME_CODE'];
    echo "<br>";
    echo $row['INCIDENT_NO'];
    }
    

     

    That results in

     

    Adam

    1

    Adam

    2

    Adam

    3

     

    Becky

    1

    Becky

    2

    Becky

    3

     

     

  6. Hi

     

    Just a quick one.

     

    I want my output result to look like this. In its simplistic form I have 2 columns, NAME and NUMBER.

     

    Adam

    1

    2

    3

     

    Becky

    1

    2

    3

     

    Charlie

    1

    2

    3

     

     

    So the output results are grouped by the "name" field, then ordered by the "number" field.

     

    I thought it was GROUP BY, but that function is something else.

     

    Iv tried searching around but im unsure what you call this form of grouping results.

     

    Many Thanks!

  7. Hi All,

     

    Im doing something for work (unpaid lol) that basically takes 2 tables, links them, then seperates out the results into "chargable" and "non chargeable" ...

     

    I need a query that will basically do this. Im going to type out what i think should happen.. 

     

    OK 2 tables, incidents and jobs.

     

     

    SELECT incidentNumber, code1 FROM incidents    ---- This gets ALL the incidents from the 1st table and returns all the $incidentNumber's aswell as $code1

     

    SELECT job FROM jobs WHERE incidentNumber = $incidentNumber  ---- This is the 2nd table with a matching incidentNumber field that the same as the 1st table incidentNumber field .

     

    AND THEN

     

    SELECT job FROM jobs where code2 = $code1  ---- this selects all the jobs with a code2 from the 2nd table that matches code1 from the 1st table.

     

    The end result is to only select incident numbers from the incidents table that have a matching code1 and code2 in the jobs table.

     

    Where do i start? i need to join the queries and the tables somehow and pass code1 as a var to the last bit when matching code1 to code2.

     

     

  8. Thanks iv got this so far...

     

    SELECT team FROM `userfields` GROUP BY team ORDER BY COUNT(team) DESC
    

     

    This successfully orders by the teams with the most fans... and i can output the team name... so i have this

     

    1. Leeds

    2. Wigan

    3. Warrington

     

    But how to i add the actual number of fans for each team?

  9. Hey

     

    ok, i have a mysql table that show which user supports which team. example table results: uid is userid and team is team name.

     

    uid  team

    3      leeds

    6      wigan

    1      leeds

    9      warrington

    2      wigan

     

    What i want to output is a "league table" showing how many supporters each team has.. the result needs to be this

     

    1. Leeds (3fans)

    2. Wigan (2fans)

    3. Warrington (1fan)

     

    This would be

     

    $position. $team ($teamFans )

     

     

    So the query needs to group by team name, then count the number of fans, then output the team name and number of fans.

     

    I can do the GROUP BY bit... and output all the team names a single time... but just lost on how im meant to count up the fans and pass $teamFans to the result..

     

    Any help?

     

  10. Hi Everyone!

     

    Really stuck with this one.. Im midway through creating a "rota" for staff at work.. and it shows whos working that day, and who isnt.

     

    For a "base" rota (unedited with no holidays/sickness etc) i need to populate the calendar i made with staff names on a 4 on 4 off basis. I was hoping php could loop round and pop the names in for me.

     

    Here's whats i have so far:

     

    $shifts1 = array("Day", "Night");
    $shifts2 = array("Night", "Day");
    $staffPair1 = array("Adam", "Ashley");
    $staffPair2 = array("Dave", "Terry");
    
    $thisMonth = date("F");
    $daysThisMonth = date("t");
    
    for ($i = 1; $i <= $daysThisMonth; $i++) {
    $calGen .= "<div id=\"calendarDays\"><div>$i</div><div>$STAFF_ON_SHIFT</div></div>";
    }
    
    

     

     

    Pair1 work together, one is on DAYS, one is on NIGHTS for 4 days/nights then both are off for 4 days, Pair2 then steps in and works the same for 4 days/nights, then off for 4 days etc etc.

     

    I need to echo $STAFF_ON_SHIFT which is who is on what shift on what date.

     

    So for example a month would be like this:

     

    Adam (D)

    Ashley (N)

    Terry (OFF)

    Dave (OFF)

     

    above x4 days - then

     

    Adam (OFF)

    Ashley (OFF)

    Terry (D)

    Dave (N)

     

    above x4 days - then

     

    Adam (N)

    Ashley (D)

    Terry (OFF)

    Dave (OFF)

     

    above x4 days - then

     

    Adam (OFF)

    Ashley (OFF)

    Terry (N)

    Dave (D)

     

    First pair switches shifts round every other 4 so Adam is on nights and Ashley on Days then off for 4 days, then Adam is on days and Ashley on nights, same for pair2 (shift switch around)..

     

    I know thats a lot to ask, but breaking it down looks "simple" lol.

     

    Assign a shift to pair1 for 4 days

    Pair 2 off for 4 days

     

    Assign a shift to pair2 for 4 days

    Pair 1 off for 4 days

     

    Repeat above but swap shifts round for each pair (nights, days)

     

    Any help? :P

     

    MANY MANY THANKS!!!!!!

     

     

     

  11. Hey all

     

    Is it possible to have a function return more than one var?

     

    For example

     

    function test() {
    //do something
    $title = "batman";
    return $title;
    }
    
    
    echo test();   // echos batman
    

     

    But what if I want to use several things from the function like $title $cast $rating etc?

     

    In separate areas around my page. Basically, I'm making a movie review page, I want a function that builds the review bits up. Then I can echo the various bits around the page.

     

    So basically can I do this?

     

    <?
    
    function buildReview() {
    // get review data from mysql 
    
    Return $title $cast $review $poster
    }
    
    Echo "<title>$title</title>
    <img src=\"$poster\">
    ";
    
    // and so on...
    ?>
    
    

     

    so instead of just echo the function, can I echo the returned vars in a function?

     

    Cheers!!

     

  12. My accountID primary key is set to INT auto increment and values range from 1 - 164512. Iv always just used INT for IDs if I'm been honest. Would you suggest I could use smallINT or mediumINT on this accountID aswell?

     

    I did read through the numerical types for mysql Colums but I just didn't understand it lol.

     

    Thanks for the help and advice, it's very helpful.

  13. I tihnk i now know what it is... its only indexing the unique (DISTINCT) teamID values. So only one indexed row per teamID, but many rows can have the same teamID ...?

     

    Im confused, why is it indexing like this? I want it to index all rows with a teamID surley? no matter if example - 10 rows all have the same teamID or not..

     

    more confused lolol.

  14. Hi,

     

    Iv got a mysql database with 70,000 rows, and in the column "teamID" iv set it to a mediumint(4) col type.  Values in the colum is a teams ID ranging from 1-4 characters so could be team id "1" .. or up to "9999" for example.

     

    But the index is only indexing 214 rows out of about 1200 rows with teamIDs other than 0.  iv tried just INT as the coltype, also varchar etc etc... doesnt seem to matter it still only indexed 214 rows...but theres 1200 rows with teamIDs... ?

     

    Iv no idea why... ? any pointers?

×
×
  • 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.