Jump to content

pro_se

Members
  • Posts

    131
  • Joined

  • Last visited

Posts posted by pro_se

  1. <?php
    $pre_toid = explode("?id=", $_SERVER['HTTP_REFERER']);
    $toid = $pre_toid[1];
    $result = mysql_query("SELECT * FROM `hub` where to_id='".$toid."'");
    $nvotes=mysql_num_rows($result);
    while($row=mysql_fetch_array($result)) {
    $dbratings = $row["rating"];
    $votes_array = array("votes" => $dbratings);
    }
    $added_votes = array_sum($votes_array);
    $divided_votes = $added_votes/$nvotes;
    $total_rating = $divided_votes; 
    ?>

     

    Ok, I got that far, but there is something wrong with the while loop. When I try and print or add the array it only prints or gets the sum of one vote from the array, and I know for a fact that there are at least 30 entries in the table.

  2. okay, I got the stupid thing to have the if/ else thing work.. now.. all I am getting is the same three friends.. all of them are the same.. how can i display all the friends different?

     

    function getfriendsforuid($puid) {
    
    $query = "SELECT * FROM `friends` WHERE `passive_id` = '$puid' AND `accpet` = 'y' LIMIT 3";
    
    $result_query = mysql_query($query);
    $numfriends = mysql_num_rows($result_query);
    $repeat = 0;
    while ($repeat < $numfriends) {
    while($fname1lname = mysql_fetch_assoc($result_query)) {
        $friend = $fname1lname["acting_id"];
    $query = "SELECT * FROM `pics` WHERE `uid` = '$friend' AND `default` = 'y'";
    $result_query = mysql_query($query);
    while($fnam2elname = mysql_fetch_assoc($result_query)) {
        $pic = $fnam2elname["path"];
    $query2 = "SELECT * FROM `user` WHERE `id` = '$friend'";
    $result_query2 = mysql_query($query2);
    while($fnamelname2 = mysql_fetch_assoc($result_query2)) {
       $uname = $fnamelname2["username"];
    $query3 = "SELECT * FROM `pics` WHERE `uid` = '$friend' AND `default` = 'y'";
    $numpics = mysql_query($query3);
    $picsfound = mysql_num_rows($numpics);
    if ($picsfound >= 1) { 
    echo "<div class=\"friendbar\"><a href=\"/profile/$fnamelname2[username]\"><img border=\"0\" src=\"/u/s_$pic\"></a></div>";
    
    }
    }
    }
    }
    if ($picsfound == 0) {echo "<div class=\"friendbar\"><a href=\"/profile/$uname\"><img border=\"0\" src=\"/u/s_np.jpg\"></a></div>";}
    $repeat++; 
    }
    }

     

    and a link to my site is: http://notexting.com/profile/cvarma

  3. Well, ok.. That Partially works... My database does not have predefined pictures... The pictures are all user uploaded and the path (or filename) is stored into a row on the database. What you gave me works fine when you are looking up images with a specific ID. I need a way to get the path with just the friends user ID. I dont know how to do all that LEFT JOIN and INNER JOIN stuff so I could not modify it to work for me.. Can you explain to me how that works or can you modify the code you sent me to get the path by looking in the 'pics' table where the ID = PUID and get the path out..

  4. Well I don't know about your tables in DB.

     

    But if your passive_id is numeric field than next query shouldn't work because of apostrophes.

    $query = "SELECT * FROM `friends` WHERE `passive_id` = '$puid' AND `accpet` = 'y' LIMIT 3";

     

    Could you show us tables from db. I think you could make it easier with JOIN method or....

    Well, the whole thing works, I just need help making the stupid thing display all the rows where the friends id matches whats in the database...

  5. yea, here is the DB Schema

    -- phpMyAdmin SQL Dump

    -- version 2.8.2.4

    -- http://www.phpmyadmin.net

    --

    -- Host: mysql.cvnetworks.net

    -- Generation Time: Apr 15, 2007 at 05:54 PM

    -- Server version: 5.0.24

    -- PHP Version: 4.4.4

    --

    -- Database: `notexting`

    --

     

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

     

    --

    -- Table structure for table `comments`

    --

     

    CREATE TABLE `comments` (

      `commentid` int(12) NOT NULL auto_increment,

      `toid` int(11) NOT NULL,

      `fromid` int(11) NOT NULL,

      `comment` text NOT NULL,

      `datetime` datetime NOT NULL,

      PRIMARY KEY  (`commentid`)

    ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

     

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

     

    --

    -- Table structure for table `friends`

    --

     

    CREATE TABLE `friends` (

      `friendshipid` int(12) NOT NULL auto_increment,

      `acting_id` int(11) NOT NULL,

      `passive_id` int(11) NOT NULL,

      `date` date NOT NULL,

      `accpet` enum('y','n') NOT NULL default 'n',

      PRIMARY KEY  (`friendshipid`)

    ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

     

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

     

    --

    -- Table structure for table `pics`

    --

     

    CREATE TABLE `pics` (

      `pid` int(11) NOT NULL auto_increment,

      `uid` int(11) NOT NULL,

      `path` varchar(50) NOT NULL,

      `default` enum('y','n') NOT NULL default 'n',

      PRIMARY KEY  (`pid`)

    ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

     

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

     

    --

    -- Table structure for table `profile`

    --

     

    CREATE TABLE `profile` (

      `id` int(11) NOT NULL,

      `aboutme` text NOT NULL,

      `im` varchar(50) default NULL,

      PRIMARY KEY  (`id`)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

     

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

     

    --

    -- Table structure for table `tags`

    --

     

    CREATE TABLE `tags` (

      `tagid` int(11) NOT NULL auto_increment,

      `uid` int(11) NOT NULL,

      `tag` varchar(20) NOT NULL,

      PRIMARY KEY  (`tagid`)

    ) ENGINE=MyISAM AUTO_INCREMENT=95 DEFAULT CHARSET=latin1 AUTO_INCREMENT=95 ;

     

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

     

    --

    -- Table structure for table `user`

    --

     

    CREATE TABLE `user` (

      `id` int(11) NOT NULL auto_increment,

      `fname` varchar(20) NOT NULL,

      `lname` varchar(20) NOT NULL,

      `username` varchar(20) NOT NULL,

      `password` varchar(32) NOT NULL,

      `email` varchar(50) NOT NULL,

      `bday` date NOT NULL,

      `gender` enum('m','f','o') NOT NULL default 'm',

      `orientation` enum('s','b','g','o') NOT NULL default 's',

      `location` varchar(50) NOT NULL default 'Fullerton, CA',

      `signup_date` date NOT NULL,

      `ip` varchar(16) NOT NULL,

      `logintimes` int(10) NOT NULL default '0',

      `lastlogin` date NOT NULL,

      PRIMARY KEY  (`id`)

    ) ENGINE=MyISAM AUTO_INCREMENT=69 DEFAULT CHARSET=latin1 AUTO_INCREMENT=69 ;

     

     

  6. Hi, I recently started an endeavor to create a friend system where it will allow people to add people as friends and I have run into quite a bit of trouble, please help.

     

    ..I am STUCK!

     

    I want to display the friends and their pictures as well as links to their page with their friends on that page. But the design of my page only allows 3 thumbnails to be displayed.

     

    I have created the code to display one friend but I cannot get it to display all the friends and limit it to only display 3.

     

    Here is the code that I have managed to create:

    <?php function getfriendsforuid($puid) {
    $query = "SELECT * FROM `friends` WHERE `passive_id` = '$puid' AND `accpet` = 'y' LIMIT 3";
    $result_query = mysql_query($query);
    while($fnamelname = mysql_fetch_array($result_query)) {
        $friend = $fnamelname["acting_id"];
    $query = "SELECT * FROM `pics` WHERE `uid` = '$friend'";
    $result_query = mysql_query($query);
    while($fnamelname = mysql_fetch_array($result_query)) {
        $pic = $fnamelname["path"];
    }
    }
    $query2 = "SELECT * FROM `user` WHERE `id` = '$friend'";
    $result_query2 = mysql_query($query2);
    while($fnamelname2 = mysql_fetch_array($result_query2)) {
        $uname = $fnamelname2["username"];
    }
    $query3 = "SELECT * FROM `pics` WHERE `uid` = '$friend' AND `default` = 'y'";
    $numpics = mysql_query($query3);
    $picsfound = mysql_num_rows($numpics);
    if ($picsfound >= 1) { 
    echo "$pic";
    echo "\" onclick=\"window.location = '/profile/$uname'\"";
    } else {
    echo "npic.jpg\" onclick=\"window.location = '/profile/$uname'\"";
    }
    } ?> 

     

    That only displays one friend.. I was thinking maybe use a while statement to get all the friends but I am not sure of the procedure.

     

    Any and all help is welcomed...

     

    Oh, and here is the function-call:

    <?php  echo "<div class=\"friendbar\" style=\"cursor:pointer;\"><img border=\"0\" src=\"/u/s_"; getfriendsforuid($puid); echo "></div>"; ?>

    -- just to put it out there...

     

    Thank you..

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