Jump to content

PHPTOM

Members
  • Posts

    84
  • Joined

  • Last visited

Posts posted by PHPTOM

  1. Hey guys,

    Basically I have this code:

    <select name="year">
    <?PHP
    for($i = 1900; $i <= date('Y'); $i++){
    echo '<option value="'.$i.'">'.$i.'</option>';
    }
    ?>
    </select>
    

    But the only problem is that it displays in the wrong order. Eg:

    1901

    1902

    1903

    ...

    2005

    2006

    2007

     

    How can I make it so it goes like this:

    2009

    2008

    2007

    ...

    1930

    1929

    1928

     

    Thanks

  2. No basically I have an external language file. It is a big array of translations. I want to echo an array, so this is a better explanation:

    language.php:

    <?PHP
    $language = array("hi" => "bonjour");
    ?>
    [/plhp]
    
    functions.php:
    [code=php:0]
    <?PHP
    include "language.php";
    class Layout{
    function Top(){
    echo $language['hi'];
    }
    }
    ?>
    

     

    However it doesnt actually echo this. It is not echoing anything.

    How can I do this?

  3. Hi all,

    Ok I have a language file and a class.

    Basically this is the class file:

    <?PHP
    include "language file";
    class Layout{
    function Top(){
    ...
    function Bottom(){
    ..
    }
    }
    ?>
    

     

    If I go to echo the $language variable, it doesn't display.

     

    How can I use variables from outside of the function/class in the function?

    so

    function Top(){
    echo $language['....'];
    }
    

     

    Thanks

  4. Hi,

    Im wanting a table to function like this:

    *table coding*

    <tr>

    <td>1</td>

    <td>2</td>

    <td>3</td>

    <td>4</td>

    </tr>

    <tr>

    <td>5</td>

    <td>6</td>

    <td>7</td>

    <td>8</td>

    </tr>

     

    I basically want it to go to a new row once it hits 4 items on the current row. Any ideas on how to do this?

    I'm off to school now, but I will be sure to have a read when I get in if anyone replies

     

    Thanks :)

     

  5. Yup, I know about examples. I added that variable to show you better, as you won't know what $a['time'] means. I'm having problems with it not working the correct hour out.

     

    <table width="100%" cellpadding="4" cellspacing="0" border="0">
    <tr>
    <td><font class="heading2">Start</font></td>
    <td><font class="heading2">End</font></td>
    <td><font class="heading2">Presenter</font></td>
    </tr>
    <?PHP
    $q = mysql_query("SELECT * FROM `timetable` WHERE `day` = '".$_GET['day']."' ORDER BY `time` ASC");
    while($a = mysql_fetch_array($q)){
    $newtime = strtotime("+2 hours", $a['time']);
    ?>
        <tr>
        <td><?=$a['time'];?></td>
        <td><?=date('H:i', $newtime);?></td>
        <td><?=$a[presenter];?></td>
        </tr>
    <?PHP } ?>
    </table>
    

     

    This is what I have dispayed:

    17:00  02:00  Tom

     

     

    Any ideas? The 02:00 should show 19:00.

  6. PHP is executed server side as normal.

    .htaccess:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^ads\.js$ ads.php
    

     

     

    ads.php:

    header('Content-type: application/javascript');
    //You can do PHP stuff. But when you want to echo stuff do document.write
    echo "document.write('hello world')";
    

     

     

    Now you can do

    <script type="text/javascript" src="ads.js" />
    

     

    I don't know if this will actually work. But there is a chance

    ----------------

    Now playing: 2pac - Changes

    via FoxyTunes

  7. Right

     

    Have a database

    Have a row called menu (used here)

    Have 3 columns called id, image and name

     

    <?PHP
    // Connect to database etc
    
    echo "<table>";
    $query = mysql_query("SELECT * FROM `menu`");
    while ($array = mysql_fetch_array($query)){
    echo '
    <tr>
    <td align="center"><a href="index.php?singer='.$array['id'].'"><img src="'.$array['image'].'" />'.$array['name'].'</a></td>
    </tr>';
    }
    echo "</table>";
    ?>
    

  8. <?php
    $con = mysql_connect("localhost","apnimusk","password");
    if (!$con){
    die('Could not connect: ' . mysql_error());
    }
    
    mysql_select_db("apnimusk_naat", $con);
    if(isset($_GET['id']) && is_numeric($_GET['id'])){
    $result = mysql_query("SELECT * FROM `albums` WHERE `id` = '".$_GET['id']."'");
    echo "<table border='1'>
    <tr>
    <th>Title</th>
    </tr>";
    while($row = mysql_fetch_array($result)){
    	echo "<tr>";
    	echo "<td>" . $row['title'] . "</td>";
    	echo "</tr>";
    }
    echo "</table>";
    }else{
    $result = mysql_query("SELECT * FROM `album`");
    echo "<table border='1'>
    <tr>
    <th>Name</th>
    <th>Age</th>
    </tr>";
    while($row = mysql_fetch_array($result)){
    	echo "<tr>";
    	echo "<td>" . $row['name'] . "</td>";
    	echo "<td>" ."<a href='?id=".$row['id']."'>".$row['age']."</a>" . "</td>";
    	echo "</tr>";
    }
    echo "</table>";
    }
    mysql_close($con);
    ?>
    

  9. <?php
    if (isset($_GET['page'])) {
    $subject_pages = get_pages_for_subject($sel_subject['id']);
    echo "<table>";
    while($page = mysql_fetch_array($subject_pages)) {
    echo " 
    <tr>
    <td align=\"center\"><a href=\"index.php?singer=" . urlencode($page['id']) . "\"><img src=\"".$page['image']."\"/>".$page['menu_name']."</a>
    </td></tr>";
    }
    echo "</table>";
    }
    ?>
    

  10. <?php
    $con = mysql_connect("localhost","apnimusk","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("apnimusk_naat", $con);
    
    // check to see if id is set
    if(isset($_GET['id']) && is_numeric($_GET['id']))
    {	
    $result = mysql_query("SELECT * FROM `albums` WHERE `id` = '".$_GET['id']."'");
    echo "<table border='1'>
    <tr>
    <th>Title</th>
    </tr>";
    while($row = mysql_fetch_array($result))
    {
      echo "<tr>";
      echo "<td>" . $row['title'] . "</td>";
      echo "</tr>";	
      }
    echo "</table>";
    }
    // no id requested, display results
    else
    {
    
    $result = mysql_query("SELECT * FROM `album`");
    
    echo "<table border='1'>
    <tr>
    <th>Name</th>
    <th>Age</th>
    </tr>";
    
    while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['name'] . "</td>";
      echo "<td>" ."<a href='?id=".$row['id']."'>".$row['age']."</a>" . "</td>";
      echo "</tr>";
      }
    echo "</table>";
    }
    ;
    }
    mysql_close($con);
    

  11. Couldn't you do something like this. I know it's an extremely bad way of doing it but I don't know any different.

    <?PHP
    $words = array(
    'baloon' => 'बलून'
    );
    ?>
    

    Then you could say:

    <?PHP
    echo "The translation of 'baloon' is: ".$words['baloon'];
    ?>
    

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