User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 422,996 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,935 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2035 | Replies: 13
Reply
Join Date: Jul 2006
Posts: 11
Reputation: jeadeb is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
jeadeb jeadeb is offline Offline
Newbie Poster

Help PHP/Mysql

  #1  
Jul 10th, 2006
Hi everyone!!

I need some help with setting up a php page that calls an sql database..

here is what I want it to do?


-firstly: a user must be able to log in(because under this login you must be able to get stats from this user)

Then the user has 3 options (links) for example:

clink chlink elink


when a user clicks a link it takes you to another page with 3 more links.

plink cnlink hlink

(these links takes you to a list of tpics.. same topics for each link)


now I guess what I want to do here is make a counter, so that it couts each time you click a specific link and adds it to a table:

for example


clink 26

chlink 23

elink 27

in a table on a web interface..

for me it gets tricky when each user under a seperate username, logging into the same database, should have unique results,,

so you can call.. how many times did jsmith click clink,, for example//


I use Apache server so I want to use php,, i actually like the language,, and I am using mysql for a database, should I need one in this project..

I think I am on the right track with this, what I have done is built a mysql database with the info above in it, and am calling the databse withphp, selecting the appropriate links above... it's just counting it !! no I am stuck!!

Please help ,, Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP/Mysql

  #2  
Jul 10th, 2006
You can create a table which contains username and names of all the 9 links (3x3). When the user login, the counter only update the number of click of this user, not others. For example:
[php]UPDATE table SET clink = clink+1, cnlink = cnlink+1 WHERE username = '$user'[/php]
Using a simple math, you can also sum up all the clicks you get for one particular link, and % of all clicks etc.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Join Date: Jul 2006
Posts: 11
Reputation: jeadeb is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
jeadeb jeadeb is offline Offline
Newbie Poster

Re: PHP/Mysql

  #3  
Jul 11th, 2006
Thanks alot!!, this forum is great... I had writers block, thanks for putting me back on track
Reply With Quote  
Join Date: Jul 2006
Posts: 11
Reputation: jeadeb is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
jeadeb jeadeb is offline Offline
Newbie Poster

Re: PHP/Mysql

  #4  
Jul 11th, 2006
Zippee!!

your help was greatly appreciated, however you suggested I make a table with username and name of links.

When I started getting down to this, I started making tables, and just confused myself all over again...(I only started using mysql and php about 3 days ago, so please bear with me)... I learn pretty quick.

this is what I started: a table with all usernames and passwords. so I could make a login page, when the user logs in, the first step must start example:

clink chlink elink (this is in a table of course)

are you suggesting that I insert the above links/all the links under each user name? and then selecting what I want to see on each page?


like:

+-------------+
-USER1
+-------------+
Reply With Quote  
Join Date: Jul 2004
Location: North East Indiana
Posts: 491
Reputation: Puckdropper is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 20
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: PHP/Mysql

  #5  
Jul 11th, 2006
Create another table with the username and the stats you want to keep. You'll then have two tables:

[Users]
Username
Password

[Stats]
Username (Foreign key* to Users.Username)
LinkA
LinkB
LinkC
LinkD

[* A foreign key requires the data in that field to be unique and linked to another field in another table. It makes sure you don't have stats for Joe User while Joe User doesn't exist in your users table, for example.]
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote  
Join Date: Jul 2006
Posts: 11
Reputation: jeadeb is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
jeadeb jeadeb is offline Offline
Newbie Poster

Re: PHP/Mysql

  #6  
Jul 12th, 2006
Thanks for the response, I will work on thsi right away.. however I am stuck with something again, I will paste the code here.. firstly some details:

there are 3 webpages involved here:

page 1

linkA ID = 1
linkB ID = 2
linkC ID = 3

page 2 (every link on page one takes you to this page below, thats why each one has an ID:

linkX ID=1
linkY ID=2
linkZ ID=3

Page 3 (all the links from page 2 takes you here)

link1
link2
link3
link4
link5
etc...


the result should be:

EXAMPLE

how many link2's of linkY from linkB have been clicked?

so you would get:

today, user1

linkX
------
linkA linkB linkC
link1 3
link2 5
link3 3
link4 1 3
etc...

linkY
-----
etc,, same until linkZ(so 3 tables with results for link X, Y and Z)

My fistp page liiks like this:

actions.php

[php]<?
$database = "strokesheet";
$user = "odbc";
$pass = "";
$hostname = "localhost";

mysql_connect ( $hostname, $user, $pass)or die("Could not connect: ".mysql_error());
mysql_select_db($database) or die(mysql_error());

$results = mysql_query("select * from actions");
$numrows = mysql_num_rows($results);
for ($i=0 ;$i<$numrows; $i++)
{
$row = mysql_fetch_array($results);
echo("<p><a href=\"companies.php?actionid=");
echo($row["actionID"]);
echo("\">");
echo($row["actionName"]);
echo("</a></p>");
}
?>[/php]


this page is perfect!!

the next page:

companies.php

[php]<?
$database = "strokesheet";
$user = "odbc";
$pass = "";
$hostname = "localhost";

mysql_connect ( $hostname, $user, $pass)or die("Could not connect: ".mysql_error());
mysql_select_db($database) or die(mysql_error());

$results = mysql_query("select * from companies");
//assume company 1
//<table>
//loop through topics
// <tr><td>$topicname</td>
//loop though actions
//select count(*) as num from strokes where actionid = x and topicid = y and companyid = 1
//<td>$num</td>
//end loop actions
//</tr>
//end loop topics
//</table>
$numrows = mysql_num_rows($results);
for ($i=0 ;$i<$numrows; $i++)
{

$row = mysql_fetch_array($results);


echo("<p><a href=\"topics.php?actionid=");

echo($actionid);

echo("&companyid=");
echo($row["companyID"]);
echo("\">");
echo($row["companyName"]);
echo("</a></p>");
}
?>[/php]


HERE IS THE PROBLEM: FINALY!!!

because I want each company ID to correspnd to actionID etc, eventually topcID...

I want to see in the url: http://blablablablabla//something?ac...=1&companyid=2 for EXAMPLE.

on page 2 above it doesnt want to work, and gives me a long explanation in the address bar(can't remeber now)

whats wrong with the code on page 2, is my question
hint: I think it has something to do with this variable i'm calling from page1: is this syntax correct?
echo($actionid);

THANKS A MILLION!!!!! any help with this project will be appreciated..
Last edited by cscgal : Jul 17th, 2006 at 7:53 pm.
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP/Mysql

  #7  
Jul 12th, 2006
It would be useful to check the source code for each page, for example in your action.php page, make sure the link created is correspond to the action id you post from one page to another. You SQL query may have to change to select * FROM companies WHERE actionID = '$actionID'. It would be very useful if you paste the error message here so myself or someone could comment on it.
Last edited by zippee : Jul 12th, 2006 at 11:08 am.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Join Date: Jul 2006
Posts: 11
Reputation: jeadeb is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
jeadeb jeadeb is offline Offline
Newbie Poster

Re: PHP/Mysql

  #8  
Jul 13th, 2006
thanks for the reply, I'ts greatly appreciated, i will generate the error and post it here, I can only do this tomorrow as the PC at work has no access to php enabled server....

thanks again..
Reply With Quote  
Join Date: Jul 2006
Posts: 11
Reputation: jeadeb is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
jeadeb jeadeb is offline Offline
Newbie Poster

Re: PHP/Mysql

  #9  
Jul 17th, 2006
here is the error I got in the in address bar after I click on

http://localhost/phpmysql/topics.php.../>&companyid=1

after I click on linkX ID=1 for example,, on page two.. like I said, if I remove, echo($actionid) ; it goes away, but I cannot follow the ID's from the previous page if I do this. please help ,, thanks alot.
Reply With Quote  
Join Date: Jan 2005
Location: Sheffield, UK
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP/Mysql

  #10  
Jul 18th, 2006
No one can see your localhost... But the text appear in the link did showed that you have problem in line 46 (?) or more precisely is you did not define $actionid in your program. If the value is post from previous page, the use $_GET or $_POST to retrieve it.
Last edited by zippee : Jul 18th, 2006 at 4:55 pm.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 3:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC