Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How Do I list from SQL?

  1. #1
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How Do I list from SQL?

    I am making a PHP thing and have the following if statements:

    My SQL i have is this:

    Code:
    CREATE TABLE `jos_mochat` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(100) NOT NULL default '',
      `url` text,
      `height` varchar(50) NOT NULL default '',
      `width` varchar(50) NOT NULL default '',
      `auto` int(11) default '0',
      `frame` int(11) default '0',
      `wlink` int(11) default '0',
      `showname` int(11) default '0',
      `scroll` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
    and i have this code in the PHP
    PHP Code:
    if ((@$_GET['wrap'] == "") && (@$_GET['page'] == "")) { 
    When this IF statement is excecuted, i need the page to retrieve 'name' from the MySQL and list them. But I also need it to retrieve the 'url' and make the page a link like this :
    <a href="chat.muslimonline.org/schat/'url'>'name'</a>

    I tried echo statements but messed it up. So can anyone help me?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Now if the variable "page"
    Quote Originally Posted by sartajc
    $_GET['page']
    is the column "name" that you refer to, then use/modify the following....

    PHP Code:
    <?php
    require('config.php'); //assuming you have all the "important" variables in this file

    $conn = @mysql_connect($server,$username,$password);
    mysql_select_db($db);

    if ((@
    $_GET['wrap'] == "") && (@$_GET['page'] == "")) {  
    /*no page or info to send to the remainder of the program, echo error message, or whatnot*/
    }

    else {
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'); //request the data from the SQL

    $qry = @mysql_fetch_array($theLink);

    echo '<a href="
    http://chat.muslimonline.org/schat/' . $qry[url] . '>' . $qry[name] . '</a>'; //echo the link

    }
    ?>
    Last edited by thetestingsite; 10-18-2006 at 05:40 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite
    Now if the variable "page" is the column "name" that you refer to, then use/modify the following....

    PHP Code:
    <?php
    require('config.php'); //assuming you have all the "important" variables in this file

    $conn = @mysql_connect($server,$username,$password);
    mysql_select_db($db);

    if ((@
    $_GET['wrap'] == "") && (@$_GET['page'] == "")) {  
    /*no page or info to send to the remainder of the program, echo error message, or whatnot*/
    }

    else {
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'); //request the data from the SQL

    $qry = @mysql_fetch_array($theLink);

    echo '<a href="
    http://chat.muslimonline.org/schat/' . $qry[url] . '>' . $qry[name] . '</a>'; //echo the link

    ?>
    will that bring up all the links?

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The above code will print out only the link that the variable "name" finds in the SQL, if you wanted to show all of the links simply edit this part:

    PHP Code:
    else {
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'); //request the data from the SQL

    $qry = @mysql_fetch_array($theLink);

    echo '<a href="
    http://chat.muslimonline.org/schat/' . $qry[url] . '>' . $qry[name] . '</a>'; //echo the link


    to this:

    PHP Code:
    else {
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'); //request the data from the SQL

    while(
    $qry = @mysql_fetch_array($theLink)) { //go through each record of the sql

    echo '<a href="
    http://chat.muslimonline.org/schat/' . $qry[url] . '>' . $qry[name] . '</a> <BR>'; //echo the info from the record that the while statement is on

    //end while
    //end else 
    and that should take care of it.
    Last edited by thetestingsite; 10-18-2006 at 06:52 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    eh....the link turned orange cause of the http:// which means its a side note and not the php. how do you make the link work with php?

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Sorry about that, I forgot to do a few minor things, I typed it in a hurry without testing or proofreading and I ended up missing a few quotation marks in the process. The better coding is as follows (this is the one that has been proofread and it should work fine with some minor altering.

    PHP Code:
    <?php
    require('config.php'); //assuming you have all the "important" variables in this file

    $conn = @mysql_connect($server,$username,$password);
    mysql_select_db($db);

    if ((@
    $_GET['wrap'] == "") && (@$_GET['page'] == "")) {  
    /*no page or info to send to the remainder of the program, echo error message, or whatnot*/
    }

    else {
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'"); //request the data from the SQL

    $qry = @mysql_fetch_array($theLink);

    echo 
    '<a href="http://chat.muslimonline.org/schat/' $qry[url] . '">' $qry[name] . '</a>'//echo the link

    }
    ?>
    or this:

    PHP Code:
    <?php
    require('config.php'); //assuming you have all the "important" variables in this file

    $conn = @mysql_connect($server,$username,$password);
    mysql_select_db($db);

    if ((@
    $_GET['wrap'] == "") && (@$_GET['page'] == "")) {  
    /*no page or info to send to the remainder of the program, echo error message, or whatnot*/
    }

    else {
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'"); //request the data from the SQL

    $qry = @mysql_fetch_array($theLink);

    echo 
    '<a href="http://chat.muslimonline.org/schat/' $qry[url] . '">' $qry[name] . '</a>'//echo the link

    ?>
    Last edited by thetestingsite; 10-19-2006 at 06:31 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Its not working. If you want to see the PHP component in action, check out http://famousmuslims.muslimonline.or...ion=com_mochat

    As you can see, it is just bringing up the error message as defined in my config file, but what i wanted was all the chatrooms to come up when it is on the index page of this component, which explains why i used the
    PHP Code:
    if ((@$_GET['wrap'] == "") && (@$_GET['page'] == "")) { 
    I wanted the list to come up if nothing else comes up, and right now it isnt. here is the code so far:

    PHP Code:
    <?php
    //* @version 1.0
    // Copyright (C) 2006 Muslim Online (Sartaj Chowdhury)
    // Based on Mambo Wrapper Component by Jason Murphy (http://www.jasonmurphy.net)
    // All rights reserved.
    //
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License
    // as published by the Free Software Foundation; either version 2
    // of the License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    // GNU General Public License for more details.
    //
    // You should have received a copy of the GNU General Public License
    // along with this program; if not, write to the Free Software
    // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    //
    // The "GNU General Public License" (GPL) is available at
    // http://www.gnu.org/copyleft/gpl.html.
    //
    defined'_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

    include (
    "administrator/components/com_mochat/mochat_config.php");
     
    $my_id $my->id;
    if ((@
    $_GET['wrap'] == "") && (@$_GET['page'] == "")) {

    $conn = @mysql_connect($server,$username,$password);
    mysql_select_db($db);

    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'"); //request the data from the SQL

    $qry = @mysql_fetch_array($theLink);

    echo 
    '<a href="http://chat.muslimonline.org/schat/' $qry[url] . '">' $qry[name] . '</a>'//echo the link



    }
    if (@
    $_GET['wrap'] == "") {
    $wrap "";
    }
    $wrap str_replace(array( "JOIN""' ""WHERE" ),array( """"""), $wrap);
    if (
    $allowpage == "1" && @$_GET['page'] != "") {
    $finalurl $_GET['page'];
    $wauto "$resizepage";
    }  else {
    $page "";
    $database->setQuery"select url, width, height, scroll, auto, frame, wlink, showname from #__mochat where name='$wrap'" );
    $results $database->loadObjectList();
    foreach (
    $results as $result){
    $wurl $result->url;
    $wwidth $result->width;
    $wheight $result->height;
    $wscroll $result->scroll;
    $wauto $result->auto;
    $wframe $result->frame;
    $wlink $result->wlink;
    $wshowname $result->showname;
    }
    if (!isset(
    $wurl)){
    $wurl "";
    }
    $finalurl "$wurl";
    }
    if (
    $my_id == "" && $regonly == "1")   {
    die(
    $notauthtext);
    } else {

    if (
    $finalurl == "") {
    echo 
    $werror;
    } else {
    if (!(
    eregi("http://chat.muslimonline.org/schat/"$finalurl) || (eregi("https://",$finalurl)))) {
    $finalurl "http://chat.muslimonline.org/schat/".$finalurl;
    }
            if (
    $wauto == "1"){
            
    //resize script
            
    $xload "iFrameHeight()";
    ?>
            
            <script language="JavaScript">
    function iFrameHeight() {
      var h = 0;
      if(document.getElementById && !(document.all))
      {
        h = document.getElementById('blockrandom').contentDocument.height;
        document.getElementById('blockrandom').style.height = h + 60 + 'px';
      }
      else if(document.all)
           {
              h = document.frames('blockrandom').document.body.scrollHeight;
              document.all.blockrandom.style.height = h + 20 + 'px';
            }
    }
    </script>
    <?php
    } else {
    $xload "";
    }
    if (!isset(
    $wheight)) {$wheight $dheight; }
    if (!isset(
    $wwidth)) {$wwidth $dwidth; }
    if (!isset(
    $wscroll)) {$wscroll $dscroll; }
    if (!isset(
    $wframe)) {$wframe $dframe; }
    if (!isset(
    $wshowname)) {$wshowname $dshowname; }
    if (!isset(
    $wlink)) {$wlink $dwlink; }
    ?>
    <script language="JavaScript">
    function blockError(){return true;}
    window.onerror = blockError;
    </script>
    <IFRAME id="blockrandom"
    onLoad="<?php echo $xload?>;"
    SRC="<?php echo $finalurl?>"
    width="<?php echo $wwidth?>" height="<?php echo $wheight?>" align=top scrolling=<?php echo $wscroll?> frameborder=<?php echo $wframe?>>Sorry, your Browser does NOT SUPPORT IFRAME.<br>You may want to Upgrade your Browser.<br><a href="<?php echo $finalurl?>" target="_blank">Click Here to see the page that was supposed to load.</a><?php echo $finalurl?></IFRAME>&nbsp<a href="http://chat.muslimonline.org">&nbsp;</a>
    <div align="center">
    <?php
    if ($wshowname == "1") {
    echo 
    $finalurl;
    }
    ?>
    <br>
    <?php
    if ($wlink == "1") {
    ?>
    <a href="<?php echo $finalurl?>" target="_blank">[<?php echo $newwindowtext?>]</a></div>
    <?php
    }
     }
        }
    ?>
    btw, everything in the component is working except this index page, for example see a chatroom in action: http://famousmuslims.muslimonline.or...chat&wrap=test

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I see, so if the user has not selected anything, by default show all of the chats. For this change the following:

    PHP Code:
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'"); 
    to this:

    PHP Code:
    $theLink = @mysql_query("SELECT * FROM `$table`"); 
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    May 2006
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite
    I see, so if the user has not selected anything, by default show all of the chats. For this change the following:

    PHP Code:
    $theLink = @mysql_query("SELECT * FROM `$table` WHERE `name`='$_GET[page]'"); 
    to this:

    PHP Code:
    $theLink = @mysql_query("SELECT * FROM `$table`"); 
    hmm...didn't work.

    Here is an interesting thing I found. In the admin version of this chat where you can change the settings, i found this code:

    admin.mochat.php
    PHP Code:
    /**
    * List the records
    * @param string The current GET/POST option
    */
    function showContacts$option ) {
            global 
    $database$mainframe;




            
    $database->setQuery"SELECT * FROM #__mochat"
            
    );
            
    $rows $database->loadObjectList();

            
    HTML_contact::showcontacts$rows$option );

    And then in admin.mochat.html.php i found this code related to the list:

    PHP Code:
    // ensure this file is being included by a parent file
    defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

    class HTML_contact {
            
            function showContacts( &$rows, $option ) {
    ?>
            <form action="index2.php" method="post" name="adminForm">
            <table cellpadding="4" cellspacing="0" border="0" width="100%">
                    <tr> 
                            <td width="100%" class="sectionname">Wrap Manager</td>


                    </tr>
            </table>
            <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
                    <tr> 
                            <th width="20" nowrap="nowrap">#</th>
                            <th width="20" class="title" nowrap="nowrap"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);" /></th>
                            <th width="20%" class="title" nowrap="nowrap">NAME</th>
                            <th width="20%" class="title" nowrap="nowrap">CHATROOM</th>
                            <th width="10%" class="title" nowrap="nowrap">HEIGHT</th>
                            <th width="10%" class="title" nowrap="nowrap">WIDTH</th>
                            <th width="50" class="title" nowrap="nowrap">AUTOSIZE</th>
                            <th width="50" class="title" nowrap="nowrap">FRAME</th>
                            <th width="10%" class="title" nowrap="nowrap">SHOW LINK</th>
                            <th width="10%" class="title" nowrap="nowrap">SHOW NAME</th>
                            <th width="50" class="title" nowrap="nowrap">SCROLL</th>

                    </tr>
    <?php
                    $k 
    0;
                    for (
    $i=0$n=count($rows); $i $n$i++) {
                            
    $row $rows[$i];
                            
    $img $row->showname 'tick.png' 'publish_x.png';
                            
    $task $row->showname 'unpublish' 'publish';
                            
    $pageNav 0;
    ?>
                    <tr class="<?php echo "row$k"?>"> 
                            <td width="20"><?php echo $i+1+$pageNav->limitstart?></td>
                            <td width="20"><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id?>" onclick="isChecked(this.checked);" /></td>
                            <td width="20%"><a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->name?></a></td>
                            <td width="20%"><?php echo $row->url?></td>
                            <td width="10%"><?php echo $row->height?></td>
                            <td width="10%"><?php echo $row->width?></td>
                            <?php                if ($row->auto) { ?>
                            <td width="50" align="center"><img src="images/tick.png"></td>
    <?php                } else { ?>
                            <td width="50" align="center">&nbsp;</td>
    <?php                ?>
    <?php                
    if ($row->frame) { ?>
                            <td width="50" align="center"><img src="images/tick.png"></td>
    <?php                } else { ?>
                            <td width="50" align="center">&nbsp;</td>
    <?php                ?>
    <?php                
    if ($row->wlink) { ?>
                            <td width="10%" align="center"><img src="images/tick.png"></td>
    <?php                } else { ?>
                            <td width="10%" align="center">&nbsp;</td>
    <?php                ?>
    <?php                
    if ($row->showname) { ?>
                            <td width="10%" align="center"><img src="images/tick.png"></td>
    <?php                } else { ?>
                            <td width="10%" align="center">&nbsp;</td>
    <?php                ?>
    <td width="20%"><?php echo $row->scroll?></td>


                    </tr>
        <?php $k $k;
                            } 
    ?>

      </table>
    Problem is that mochat.php doesnt have a mochat.html.php . hmmm...Does this help at all?

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    is there any way that you could send me the entire program and I could take a look at it to see if I can figure it out. The two pieces of code above don't help out that well...sorry
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

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