Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11

Thread: array

  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts

    array

    Hi there ive been learning php for awhile and slowly getting there, however this one stumps me . here goes

    Its an array that will show a description of whats on today, our radio station with title of show , time and description. The last part of the array says pic to display A png file to be displayed for example it is Rex.png....Now all this is called from a Div Class and prints to the screen ok except REx.png we need to print the picture to the screen and not the words. If any one can write me abit of code so i can get this working . see example at vikingradio.net at the top left


    [thearray array("start" => 2, "end" => 6, "descr" => "JUKEBOX HOT 100","descr_long"=> "Non Stop Music to take you through the night","pic" => "rex.png"),]

    the code

    [
    if ($i==$showK) echo "<div class='showtime'>" .str_pad($tShow->start,2,"0",STR_PAD_LEFT) . ".00-" . str_pad($tShow->end,2,"0",STR_PAD_LEFT). ".00</div>";
    if ($i==$showK) echo "<div class='descr'>" . $tShow->descr;
    if ($i==$showK) echo "<div class='descr_long'>". $tShow->descr_long;
    if ($i==$showK) echo "<div class='pic'>". $tShow->pic;

    ]

    my opinoin somehow i have to convert the class pic to echo the image am i right??????????????


    ron
    Last edited by ronuk99; 04-16-2013 at 05:39 AM. Reason: recheck

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    134
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Put it within <img> tags so that it knows you are displaying an image, not just a string



    Code:
    if ($i==$showK) echo "<div class='pic'><img src='. $tShow->pic."'>";
    Last edited by itxtme; 04-16-2013 at 10:48 AM.

  • Users who have thanked itxtme for this post:

    ronuk99 (04-16-2013)

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts
    thanks for your reply i will give this a go at vikingradio.net. will reply again to let u know. ron

  • #4
    New Coder
    Join Date
    Jun 2012
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts
    can anyonr help getting this error now after entering the above code

    Warning: Unexpected character in input: '\' (ASCII=92) state=1

  • #5
    New Coder
    Join Date
    Jun 2012
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by itxtme View Post
    Put it within <img> tags so that it knows you are displaying an image, not just a string



    Code:
    if ($i==$showK) echo "<div class='pic'><img src='. $tShow->pic."'>";
    Warning: Unexpected character in input: '\' (ASCII=92) state=1


    hi there getting this error hope u can help me

    ron

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    What is in $tShow->pic? The only time I've seen the above warning is when using a namespace and accidentally running through a pre-5.3 PHP parser. Since the code you have posted above isn't exactly PHP code (what's with the square brackets?), I question if you are running through an eval and improperly interpreting a windows filepath. This would kinda work in a 5.3+ parser as it would try to dereference it as a namespace, but in <5.3 it'll just throw an error.
    Add a var_dump($tShow); as well as posting the actual code in use.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    New Coder
    Join Date
    Jun 2012
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Heres the code normally works fine then from another forum someone suggested the code i sent you to add an image. Thiis the won.php file


    The array code is data.php i have entered below. really appreciate your help on this. if its quite a lenghy job for u then happy to pay you something to get it to work with image. all below for you to see



    WON.PHP


    All other data works fine and after putting the image from array was getting error
    PHP Code:
    <?php

    include("data.php");

    echo 
    "<div class='Shows'>";
    echo 
    "<div class='day'>" date("l",strtotime($showday)) . " <i>now: " date("D G:i:s") . "</i></div>";
    for (
    $i=$Si;$i<$Ei;$i++) {
        
    $tShow = (object) $thisShows[$i];

        if (
    $tShow->end >= 24$tShow->end -= 24;

        echo 
    "<div class='Sitem'>\n";
        
        echo 
    "<div class='indicator'>" . ($i==$showK?"<img src='/whatsOnNow/onAirNow.png' alt='ON AIR NOW' />":"&nbsp;") . "</div>";//echo '<img src="'.$playing.'">';
        
    echo "<div class='showtime'>" str_pad($tShow->start,2,"0",STR_PAD_LEFT) . ".00-" str_pad($tShow->end,2,"0",STR_PAD_LEFT) . ".00</div>";
        echo 
    "<div class='descr'>" $tShow->descr;
            if (
    $tShow->descr_long) echo "<div class='descr_long'>" $tShow->descr_long "</div>";

    if (
    $i==$showK) echo "<div class='pic'><img src='. $tShow->pic."'>";

        echo "</div>";
        echo "<div class='
    sep'></div>";
        echo "</div>\n";
    }
        echo "<p class='
    pclear></p>n";
    echo "
    </div>";

    ?>






    The data.php . This holds the array


    PHP Code:
    $shows["wed"] = array(
       
        array(
    "start" => 0"end" => 6"descr" => "JUKEBOX REQUESTS""descr_long" => ""),
        array(
    "start" => 6"end" => 7"descr" => "RADIO OUTREACH""descr_long" => ""),
        array(
    "start" => 7"end" => 8"descr" => "JUKEBOX POWER-PLAY""descr_long" => ""),
        array(
    "start" => 8"end" => 11"descr" => "BREAKFAST SHOW ""descr_long" => ""),
        array(
    "start" => 11"end" => 12"descr" => "CHRIS MUNDAY"),
          array(
    "start" => 12"end" => 14"descr" => "RODNEY COLLINS"),
        array(
    "start" => 18"end" => 19"descr" => "THE HAPPY HOUR"),
        array(
    "start" => 19"end" => 20"descr" => "HENRY O'DONOVAN 90S SHOW"),    
       
    /*** don't change the lines below ... :) ***/

    $allDays array_keys($shows);
    sort($allDays);

    date_default_timezone_set("Europe/London");

    $today strtolower(date("D"));
    $thisHour date("G");

    //Just for testing
    /*
    $shows["wed0"] = array(
        array("start" => 00, "end" =>19, "descr" => "JUKEBOX HITS", "descr_long" => ""),
        array("start" => 19, "end" => 20, "descr" => "HAPPY HOUR 19",
        array("start" => 20, "end" => 21, "descr" => "HAPPY HOUR 20"),"descr_long"=> "Calder presents another help and advice .relationships, love or general advice are some of the problems.what would you do?. Listen in to find out and give your opinion. ","pic" => "rex.png"),
        array("start" => 21, "end" => 22, "descr" => "HAPPY HOUR 21"),
        array("start" => 22, "end" => 23, "descr" => "LEE VINCENT SHOW 22"),    
        array("start" => 23, "end" => 24, "descr" => "80S SHOW 23"));
    $UKTime = time() + 3600*12;
    $today = strtolower(date("D",$UKTime));
    $thisHour = date("G",$UKTime);
    //echo date("d.m. D G:i:s",$UKTime);
    */

    if ($shows[$today]) {   //today
        //on air??
        //if ($shows[$today][0]["start"] <= $thisHour && $shows[$today][count($shows[$today])-1]["end"] > $thisHour) {
        
    if ($shows[$today][0]["start"] <= $thisHour) {
            
    $thisShows $shows[$today];
            
    $showday $today;
            
    $onAir true;
        } else {
            
    //the day before
            
    $showday $allDays[count($allDays)-3];
            
    $thisShows $shows[$showday];
        }
    }
    //no today???
    if (!$thisShows) {
        
    $showday $allDays[count($allDays)-2];
        
    $thisShows $shows[$showday];
    }

    $cntS count($thisShows);

    //find key
    if ($onAir) {
        for (
    $i=0;$i<$cntS;$i++) {
            if (
    $thisShows[$i]["start"] <= $thisHour && $thisShows[$i]["end"] > $thisHour) {
                
    $showK $i;    //showkey
                
    $won true;    //any show onair now
                
    break;
            }
        }
    }
    //find end and start key
    if ($won && in_array($showK,array(0,1))) { //first or within the first 2 entries
        
    $Si 0$Ei 4//echo "first 2";
    } elseif ($won && ($showK == || $showK 4)) { //first or within the first 4 entries
        
    $Si $showK-1$Ei $showK+3//echo "first 4";
    } elseif ((!$showK && !$won) || $showK == ($cntS-1)) {   //no show or last one
        
    $Si $cntS-4$Ei $cntS//echo "no show or last one";
    } elseif ($showK >= $cntS-3) { //within the last 4 entries
        
    $Si $cntS-4$Ei $cntS//echo "last 4";
    } else { //anywhere between
        
    $Si $showK-1$Ei $showK+3//echo "anywhere";
    }

    //recheck of range
    if ($Si $cntS-4) { //first show within the last 4 items
        
    $Si $cntS-4$Ei $cntS;
    }
    if (
    $Ei $cntS) { //last key too high
        
    $Si $cntS-4$Ei $cntS;
    }
    if (
    $Si 0) { //first key too low
        
    $Si 0$Ei $cntS;
    }


    ?> 
    sorry about the brackets in my reply this was error.
    my email wilkinfo@gmail.com



    Ron
    Last edited by Fou-Lu; 04-17-2013 at 06:00 PM.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Let me wrap this in [php][/php] tags, and I'll take a closer look and get back on it.
    [edit]
    BTW, is data.php just missing the <?php tag on the forum here, or is it missing in the file as well?
    As well, can you post the whole error? It includes the line number as a part of either the warning or the parse error that should follow it.

    Edit:
    I can't run it through a lint test atm, but this here isn't correct syntax wise:
    PHP Code:
    if ($i==$showK) echo "<div class='pic'><img src='. $tShow->pic."'>";

        echo "</div>";
        echo "<div class='
    sep'></div>";
        echo "</div>\n";
    }
        echo "<p class='
    pclear></p>n";
    echo "
    </div>"; 
    Notice the red? That's caused by the first line where there is a premature end double quotation. That *shouldn't* give you the error you have, at least not on that line though. Change that to this:
    PHP Code:
        if ($i==$showK)
            echo 
    "<div class='pic'><img src='{$tShow->pic}'>"#rofls somehow I missed the single quote when adding the complex evaluation braces

        
    echo "</div>";
        echo 
    "<div class='sep'></div>";
        echo 
    "</div>\n";
    }
        echo 
    "<p class='pclear></p>n";
    echo 
    "</div>"
    Also note the ending brace. Since you don't have the indentation levels set quite properly and are using the single-line evaluation, that brace is the termination point for the for loop even though it *looks* like it belongs to the if ($i == $showK) block. That probably isn't incorrect though, it matches what I'd expect to see for it. Just something to note as the readability is a bit down because of it.
    Last edited by Fou-Lu; 04-17-2013 at 06:09 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    New Coder
    Join Date
    Jun 2012
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Im indeed very pleased if u need any further work ill be happy to work with you



    ron

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    See my edit above; change that up first and we'll go from there. It *shouldn't* be triggering the error you are seeing though (that should trigger a T_CONSTANT_ENCAPSED_STRING error instead).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    ronuk99 (04-18-2013)

  • #11
    New Coder
    Join Date
    Jun 2012
    Posts
    28
    Thanks
    6
    Thanked 0 Times in 0 Posts

    from ron thanks

    Thank you so much for your help here . Appreciated 1000% . im also learning so another plus. ok vikingradio.net shows image placement. its flashing on and off can i stop this . no problem if not im thankful for what u have done here


    Ron
    Vikingradio.net


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •