Welcome! Log In Create A New Profile

Advanced

portfolio oop4 and oop5 page

Posted by Rafeeq 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
portfolio oop4 and oop5 page
April 02, 2012 10:34AM
Hi I have two questions regarding these two pages.

1. the Sql code for user_friends. the primary key is user_friend_id but the text in the tut letter the id goes up to 6 and then repeats 5 over and over again see below it should be until 10.
Language: SQL
INSERT INTO `user_friends` (`user_friend_id`, `user_id`, `friend_id`) VALUES (1, 1, 3), (2, 1, 5), (3, 2, 2), (4, 2, 5), (5, 3, 4), (6, 3, 2), (5, 4, 1), (5, 4, 2), (5, 5, 1), (5, 5, 3);
2. The return link to previous page. Should it return to the previous oop4 page or if a user clicked on oop1 then oop4 page the return link should return too oop1 page?
avatar
Mac
Re: portfolio oop4 and oop5 page
April 02, 2012 10:51AM
Rafeeq Wrote:
-------------------------------------------------------
> Hi I have two questions regarding these two
> pages.
>
> 1. the Sql code for user_friends. the primary key
> is user_friend_id but the text in the tut letter
> the id goes up to 6 and then repeats 5 over and
> over again see below it should be until 10.
>
Language: SQL
> INSERT INTO `user_friends` (`user_friend_id`, > `user_id`, `friend_id`) VALUES > (1, 1, 3), > (2, 1, 5), > (3, 2, 2), > (4, 2, 5), > (5, 3, 4), > (6, 3, 2), > (5, 4, 1), > (5, 4, 2), > (5, 5, 1), > (5, 5, 3); >

An intended error who now doubt will leave a few scratching their heads.

> 2. The return link to previous page. Should it
> return to the previous oop4 page or if a user
> clicked on oop1 then oop4 page the return link
> should return too oop1 page?

Since the drop-down will present me with many select options, I need to a link to return to the drop-down again. Of course, one can present the drop down again with the result.
Re: portfolio oop4 and oop5 page
April 05, 2012 09:47PM
Mac,

On point number 1

A primary key uniquely identifies each record in a database table, so how can we have the primary key value "5" with 5 different sets of values for its 2 columns?

When I try to insert these records manually in phMyAdmin I get the follwing error when I come to the second "5" in user_friend_id

MySQL said: Documentation
#1062 - Duplicate entry '5' for key 'PRIMARY'

All the previous records seem to insert fine. When you say intended error, is this something we need to set in phpMyAdmin or did you make that error on purpose?smile

***Lets go back to my place and I will show you my source code***
avatar
Mac
Re: portfolio oop4 and oop5 page
April 10, 2012 06:41AM
I posted: An intended error who now doubt will leave a few scratching their heads.

So fix it....
Re: portfolio oop4 and oop5 page
April 22, 2012 12:52AM
Sir with regards to the drop down list should we use sql to put the names from the database or to we "load" them ourselves i.e
Language: HTML
<select > <option value="Peter Pan">Peter Pan</option> </select>
avatar
Mac
Re: portfolio oop4 and oop5 page
April 23, 2012 08:17AM
It must be loaded from the database - else it would be very easy to do!
Re: portfolio oop4 and oop5 page
April 24, 2012 01:57AM
Me again I'm not if I understand the instruction for oop4 and oop5. as it stand my understanding is If the user selects a person from the drop-down list the oop4 page passes the data to the user_find.php which prints the lines as shown in the screenshot. Am I correct ? if not can Sir please rephrase the instructions
avatar
Mac
Re: portfolio oop4 and oop5 page
April 24, 2012 06:45AM
See the post in topic oop5
Re: portfolio oop4 and oop5 page
April 24, 2012 11:34AM
hi guys, has anyone figured how to fix the duplicate key error message. I seem to be stuck on this one, plse help.
Re: portfolio oop4 and oop5 page
April 27, 2012 12:55AM
Me again, can someone plse help, am trying to populate the drop down list but it does not seem to work. Have tried populating a table and it seems to b working fine. Plse advise where I am going wrong. Thanks!
Re: portfolio oop4 and oop5 page
April 30, 2012 08:22AM
Maybe paste some of your code where you attempted to populate the drop down list, and we can try to help you where you went wrong?

(I found lots of help on this on the internet.)

---------------------------------------------------------------------
Live life...
---------------------------------------------------------------------
Re: portfolio oop4 and oop5 page
May 02, 2012 10:39AM
Hi people, plse help. I have uploaded my oop4 files to the website but when I click the oop4 link, instead of it loading my drop down menu with the uploaded data it is giving me a "couldn't connect to server message" Plse assist. Thx
avatar
Mac
Re: portfolio oop4 and oop5 page
May 02, 2012 11:19AM
You continue to ask very wide questions, and as such will be ignored until you provide more information.
Re: portfolio oop4 and oop5 page
May 02, 2012 01:57PM
I have just entered PHP/Mysql HELL!! It's been 2 days of complete confusion and I think I need some help. I have no problem with the database and the users and user_friends tables, same goes for populating the drop down combo box from the database, but I am battling to link the combo box with user.php to give the correct output. I would appreciate any and all help.
I just need some fresh input to push me in the right direction. Thanks in advance.

user_find code
Language: PHP
  1. <?php
  2. include(';user.php';);
  3. $con = mysql_connect("......") // you show this anyone can access your code!
  4. or die ("Could not connect to server");
  5. or die ("Could not select database");
  6.  
  7. ?>
  8. <form action="user_find.php"method="post">
  9.  
  10. <select name="user">
  11.  
  12.  
  13. <?php
  14. //tip: if form is submitted
  15. $query="SELECT full_name FROM users";
  16. $result=mysql_query($query);
  17. while($row=mysql_fetch_array($result))
  18. {
  19. $name=$row[full_name];
  20. echo "<option>
  21. $name
  22. </option>";
  23. }
  24. ?>
  25. </select>
  26. <input type="submit" value="Submit">
  27. </form>
  28. <?php
  29. echo "<p>User name: ".$_REQUEST["user"];
  30. ?>
  31.  
  32.  
  33. <?php
  34. $user=new User();
  35. $user->getUserById($user_id);
  36. echo "<p>User known as: ".$user->getDisplayName()."</p>";
  37.  
  38.  
  39. $friends=$user->getFriends();
  40.  
  41. echo "<p>Friends with: ".implode(';,';,$friends) . "</p>";
  42.  
  43.  
  44. .......
  45.  
  46.  
  47.  
  48. //tip: else show a form with the list of users as shown in the screenshot in oop4
  49.  
  50.  
  51. ?>
  52.  
  53.  
  54.  
  55. <?php
  56. mysql_close($con);
  57. ?>


user.php code
Language: PHP
  1. <?php
  2. class User
  3. {
  4. public function getUserById($user_id)
  5. {
  6.  
  7. $sql ="SELECT first_name,last_name,display_name FROM users WHERE user_id=';$user_id';";
  8. $....
  9. }
  10.  
  11. }
  12. ?>
avatar
Mac
Re: portfolio oop4 and oop5 page
May 02, 2012 02:12PM
Language: PHP
if($submit==';Submit';){ // manage the form input and show friends } else {   // show form   }

Do not post complete selections of code!
Re: portfolio oop4 and oop5 page
May 02, 2012 02:54PM
Sorry and thanks at the same time thumbs up
Re: portfolio oop4 and oop5 page
May 09, 2012 03:37PM
Hi
I have got everything working for the oop4.php, but when I select the name from the dropdownlist box, Peter Pan's info is displaying, no matter which one is selected. I think the problem is in the declaration of the $ID variable. So the program is only seeing Peter Pan. Please assist I'm out of ideas where to look.

Language: PHP
if(isset($_REQUEST["users"])){ $sql = ';SELECT * FROM users';; $results = mysql_query($sql) or die("Query failed: ". mysql_error()); $row = mysql_fetch_array($results); $ID = $row[';user_id';]; $user = new User(); $user->getUserById($ID);

Regards
Re: portfolio oop4 and oop5 page
May 09, 2012 05:40PM
Correct me if Im wrong but your logic reads like this:
1. Do a select all from the users table (so you are going to get all the rows back)
2. Then you get the user_id and save it in the ID variable - if you do this your results from the select will be pointing at the first row and thus the first user_id will be passed in.
Should you have populated your data with Elvis as the first row all you would be getting is Elvis's stuff.

Nowhere in your code do you pass in or use the drop down list's selected value.

---------------------------------------------------------------------
Live life...
---------------------------------------------------------------------
Re: portfolio oop4 and oop5 page
May 10, 2012 09:43AM
Jey!!! Nailed it... thanks sooooo much Bokkie.
Re: portfolio oop4 and oop5 page
May 10, 2012 11:12AM
Hi can someone plse help, I have managed to create the drop down selection list but each time I select any name it gives me the same details for Roo. Can you plse advise what I am doing wrong. Here is a snippet of my code. Thanks

Language: PHP
<?php if($_POST[';formSubmit';] == "Submit") {   $user=new User(); $user->getUserById($ID); echo "<p>User known as: ".$user->getDisplayName()."</p>";     $friends=$user->getFriends(); echo "<p>Friends with: ".implode(';,';,$friends) . "</p>";   $user->getUserById($ID); echo "<p>User known as: ".$user->getDisplayName()."</p>";
Re: portfolio oop4 and oop5 page
May 10, 2012 01:05PM
ethleejak

Where do you assign the value for $ID?

---------------------------------------------------------------------
Live life...
---------------------------------------------------------------------
Re: portfolio oop4 and oop5 page
May 10, 2012 02:31PM
My next problem.... oop5.php.
I tried two different approaches:
1. Change the getFriends() to display the first_names instead of the user_id, but then I everyone's names, not just the friends. I tried to SELECT FROM both tables.
Language: PHP
public function getFriends(){ $sql = ';SELECT users.first_name FROM users, user_friends WHERE user_friends.friend_id =';. $this->user_id; $results = mysql_query($sql) or die ("Query2 failed: ". mysql_error());

2. Write a new function showFriends(), that take the getFriends() return value as an argument. But then I get a query error in WHERE clause....
Language: PHP
public function showFriends($friendID){ $sql = ';SELECT first_name FROM users WHERE user_id =';. $friendID; $results = mysql_query($sql) or die("Query3 failed: ". mysql_error()); $friendNames = array();
Re: portfolio oop4 and oop5 page
May 10, 2012 04:32PM
1. Might be a problem with your join. Try to run your sql in mySQL and see if it returns everything, and if so make the needed tweeks.

2. Before you pass in and run $sql, first echo it out to screen and see if your query looks and contains the right values that you think it should.
Also run this in mySQL to see the outcome and work with errors there before you copy back into php.
Same for number 1, echo out the sql first before running it...

This is just all ways to help you debug. Using echo as a means of debugging issues is priceless smiling smiley

---------------------------------------------------------------------
Live life...
---------------------------------------------------------------------
Re: portfolio oop4 and oop5 page
May 11, 2012 11:14AM
Hi

I have done as you have suggested and first test the JOIN in Mysql and the correct tables and fields are returned.

I think the problem is with my while loop, as everyone's names are displayed.

Language: PHP
$results = mysql_query($sql) or die ("Query2 failed: ". mysql_error()); while ($row = mysql_fetch_array($results)){ echo "<tr><td>Friends with ". $row[';first_name';]. " ". $row[';last_name';]. "<br>"; }

Thanks
Re: portfolio oop4 and oop5 page
May 11, 2012 11:36AM
I have started uploading my pages with freeoda, including the database.

I have exported the database (using phpMyAdmin) and saved it as import1, as stipulated by freeoda. I have created the database on freeoda and received the database username ect. Then I have uploaded the database, it said the database order was added to the server queue. How long does this takes, because I did this about 2 hours ago and it still shows on the webpage that it couldn't connect to database.

Did I miss a step??
avatar
Mac
Re: portfolio oop4 and oop5 page
May 11, 2012 03:19PM
Freeoda sometimes is very slow. This is the first time I have heard about this. Log out and in again and check. Else, if the need becomes urgent, find another hosting service. Pressure smiling smiley
Re: portfolio oop4 and oop5 page
May 11, 2012 03:53PM
Or instead of importing your db, create from scratch - it should go quick not a lot of data and tables.

---------------------------------------------------------------------
Live life...
---------------------------------------------------------------------
Sorry, you do not have permission to post/reply in this forum.