Log in

View Full Version : Using data from MySQL



Rob (SA)
10-17-2010, 05:17 PM
Hi Folks,

I am busy developing a page which has a custom html in it.

In adding the script / php I have got to a point and for some reason cannot add additional information to this page / custom html.

Any advice here would be welcome

See also: http://www.dynamicdrive.com/forums/showthread.php?p=239416

jscheuer1
10-17-2010, 05:27 PM
Most likely you made a syntax error somewhere that's stopping additional content being added. However, pages should not be overloaded. But there is no limit to what you can put on an HTML page. PHP has certain buffering/cache limitations in regards to certain operations which require them. Some operations require the code to wait for things, this must be built in where applicable. And PHP must be written correctly and logically or else it will throw a warning or an error in an unexpected spot that might throw everything else off.

Other possible problems causing this:


a die() or exit() in your PHP code that stops all further processing
an unclosed HTML comment tag that renders the rest of the page after it as a comment.
a javascript error that halts all further javascript processing


There could be other things.

Rob (SA)
10-17-2010, 05:36 PM
Hi John,

Thanks for the reply.

I think what I have done is pretty tidy - as a person not knowledgeable of php. It is pretty consequential and repetitive so I am at a loss as to what could be the constraint.

The page is not a dynamic setup but rather a static setup and maybe that is were problems are occuring?

The page can be veiwed here (http://www.gnjgf.co.za/Glacier_payfast.php)

From the word Erinvale I am trying to edit the page and I am not being allowed to.

I look forward to your replies

Regards
Rob

jscheuer1
10-17-2010, 06:05 PM
I see 12 entries after ERINVALE. What browser are you using? Or do you mean something else when you say, "From the word Erinvale I am trying to edit the page and I am not being allowed to"?

There is an error in the generated HTML code here:


<tr class="alt">
<td>PAARL</td>
<td>05 JULY 2011</td>
<td>?</td>
<td>OPEN/CLOSED</td>
<td><form action="https://www.payfast.co.za/eng/process" method="post">
<input type="hidden" name="cmd" value="_paynow">
<input type="hidden" name="receiver" value="junior@hayesgolf.co.za">
<input type="hidden" name="item_name" value="Payment - Paarl - Glacier Series">
<input type="hidden" name="item_description" value="payment">
<input type="hidden" name="amount" value="120.00">
<input type="hidden" name="return_url" value="http://www.gnjgf.co.za/entryform.php">
<input type="hidden" name="cancel_url" value="http://www.gnjgf.co.za/Glacier_Main.html">
<input type="submit" style="width:66px;height:20px;background-color:#B5CCE4;font-size:10px; font-family: arial, sans-serif;" value="PAY NOW">
</td>

</tr>>

But all that appears to do is add (highlighted) here:


UPCOMING TOURNAMENTS ARE LISTED BELOW
>

At the end of the served source, there is this:


<!---------------------------

</table>
</body>
</html>
</div>
</div>
</body>
</html>

All those closing tags are implied anyway, so they aren't 'missed' by the browser. However, anything added after that highlighted line will appear to be part of an unclosed HTML comment and will not be displayed.

You could try running the PHP code that makes this on its own in such a way that any errors or warnings will be displayed.

If that doesn't clear it up for you and if the problem is with PHP, I need to see the PHP code.

Rob (SA)
10-17-2010, 08:56 PM
Hi John,

Thanks for taking a look at the file.

I have made those changes suggested - much appreciated.

When I try attach the entire file for your perusal - it asks me to reduce the size of the file to 10 000 characters from 30228.

Is there perhaps another way I can foward you the file for inspection.

Regards
rob

Rob (SA)
10-17-2010, 09:07 PM
Hi John,

I reply to some other questions:

I am using IExplorer as a browser.

From the word Erinvale I am trying to edit the html file so as to have the same visual effect and result as everything above it (bar the last item)

Howvever the problem of entering any further is restricted as explained earlier.

With your experiance you would be able to see why - I however cannot find the error.

I look forward to your assitance.

I attach my [email mercifully removed] if this be the only manner to forward you the file.

Regards
Rob

traq
10-17-2010, 10:55 PM
Hi John,

Thanks for taking a look at the file.

I have made those changes suggested - much appreciated.

When I try attach the entire file for your perusal - it asks me to reduce the size of the file to 10 000 characters from 30228.

Is there perhaps another way I can foward you the file for inspection.

Regards
rob

you can post the file as an attachment (change the extension from php to .txt).

jscheuer1
10-18-2010, 02:10 AM
I removed your email from your post. It's just an invitation to spammers to send you all manner of unsolicited junk.

Feel free to PM me your email address. But, as traq says, you should be able to attach the file as a .txt version.

Let's put that to one side for a moment though, go ahead and attach it, I may well need it, but I still want to know what exactly you mean by:


From the word Erinvale I am trying to edit the html file so as to have the same visual effect and result as everything above it (bar the last item)

I think I get what you're saying, that ? for the ROYAL CAPE row's ENTRY STATUS column followed by all those OPEN/CLOSED entries in the ENTRY STATUS column for subsequent rows until the UMKOMAAS row. But I'm not sure. If that's what it is, perhaps there's nothing wrong with the PHP, rather the database just doesn't have entries for those tables/records.

Regardless, though I'd still like to know if I've got that right, I'm at least a little puzzled by your use of the term "edit". What exactly do you mean by that?

Rob (SA)
10-18-2010, 03:59 AM
Hi Guys,

I appreciate your efforts to assist.

The file created needs to have changes made in order that the functionality improve.

The "CLOSED/OPEN" needs to reflect in "OPEN" in Blue as this shows to me that the change made to that row includes for the if then statement that I have introduced.

I have been able to make the changes where the color blue can be seen.

I cannot change /edit the remainder as the change requires additional input or ammendments to what already exists.

In terms of sending the .txt file - thank you for "mercifully" protecting my email address.

I tried that option but we are limited to 19.5Kb of file size. This file is ±35.2Kb

I will therefore try the PM option in order to get the file to you some how.

Agian I appreciate your time and effort

Regards
Rob

jscheuer1
10-18-2010, 04:31 AM
I cannot change /edit the remainder as the change requires additional input or ammendments to what already exists.

I'd still like more on what "edit" means here. I'm beginning to think you just mean something like:

"make the served source code look the way I want it to"

Have I got that right?

Anyways, I was going to say before but didn't because I figured your file probably wasn't as large as you now indicate that it is, that you could zip it and attach the .zip version.

That is if you want other forum members to be able to weigh in on it.

If not, email it to me as an attachment. I will email you my address after posting this.

Rob (SA)
10-18-2010, 05:26 PM
Hi John,

I have sent you mail - thanks for the contact details.

By edit I mean the following:

I have some script that looks like this and what you see here produces the information one would see on a row of the page in question.


<tr class="alt2">
<td>WANDERERS</td>
<td>18 SEPTEMBER 2011</td>
<td>?</td>
<td>OPEN/CLOSED</td>
<td><form action="https://www.payfast.co.za/eng/process" method="post">
<input type="hidden" name="cmd" value="_paynow">
<input type="hidden" name="receiver" value="junior@hayesgolf.co.za">
<input type="hidden" name="item_name" value="Payment - Wanderers - Glacier Series">
<input type="hidden" name="item_description" value="payment">
<input type="hidden" name="amount" value="120.00">
<input type="hidden" name="return_url" value="http://www.gnjgf.co.za/entryform.php">
<input type="hidden" name="cancel_url" value="http://www.gnjgf.co.za/Glacier_Main.html">
<input type="submit" style="width:66px;height:20px;background-color:#B5CCE4;font-size:10px; font-family: arial, sans-serif;" value="PAY NOW">
</td>

</tr>

After it has been edited the information as seen above would now look like this


<tr class="alt2">
<td>WANDERERS</td>
<td>18 SEPTEMBER 2011</td>
<td>?</td>
<?php
if($num_rows >= 80){
echo '<td><font style="font-size:11px" color="Red" face="Arial">CLOSED</td>
<td>&nbsp;</td>';
}
else {
echo '<td><b><font style="font-size:11px" color="Blue" face="Arial">OPEN</b></td>
<td><form action="https://www.payfast.co.za/eng/process" method="post">
<input type="hidden" name="cmd" value="_paynow">
<input type="hidden" name="receiver" value="junior@hayesgolf.co.za">
<input type="hidden" name="item_name" value="Payment - Wanderers - Glacier Series">
<input type="hidden" name="item_description" value="payment">
<input type="hidden" name="amount" value="120.00">
<input type="hidden" name="return_url" value="http://www.gnjgf.co.za/entryform.php">
<input type="hidden" name="cancel_url" value="http://www.gnjgf.co.za/Glacier_Main.html">
<input type="submit" style="width:66px;height:20px;background-color:#B5CCE4;font-size:10px; font-family: arial, sans-serif;" value="PAY NOW">
</td>
';
}
?>
</tr>

I hope this help in providing information as to how I edit my file.

Thanks again for you help

jscheuer1
10-18-2010, 11:03 PM
So this is some sort of limitation of your editor? I can edit the file you sent me to make it look like you want. Even NotePad can do that. What editor are you using?

Anyways, the file you sent cannot be the whole deal. It makes frequent reference to:


if($num_rows >= 80){

But $num_rows is never defined nor (as is implied it should be by the above test) incremented in it.

So I would tend to assume that the file you sent me is an include to another file that has that information/process on it.

But I would also observe that what you have in the file you sent seems awfully redundant. This leads me to believe that perhaps it's a generated file, or should be. Is it?

If so, I need the file that makes it. If not, we need to make it a generated file by creating a file that will generate it.

Do you have a database? Is that where all of this is coming from?

Rob (SA)
10-19-2010, 03:56 AM
Hi John,

Thanks for the reply.

Your are correct in noticing that I make reference to another file.

I am trying to vreate a tournament entry form that will limit the field isze to 80. The information is doen via MySQL and ideally the excercise would be that if the emtries are equal to or greater tha 80 the player will not be able to enter.

If one veiws the file (http://www.gnjgf.co.za/Glacier_watflip.php) then the information that is produced in the left hand column will determine my result.

So yes you are correct the two need to be linked.


<?php

$connect = mysql_connect("localhost", "e****a_r***t", "r****h") or

die ("Hey loser, check your server connection.");

mysql_select_db("eghfya_Members");

$quey1="select * from _Form_Nr_3 ORDER BY `i_wish_to_play` ASC, `surname` ASC ";
$result=mysql_query($quey1) or die(mysql_error());


?>
<!------------------------------------------------------------------>
<! THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE >
<!------------------------------------------------------------------>
<table border=1 width="85%" bordercolor="#D3E2FE" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" style="font-size:11px" cellspacing=0>
<!------------------------------------------------------------------>
<! THIS SECTION CHANGES THE MAIN HEADING >
<!------------------------------------------------------------------>
<caption><b><font style="font-size:20px" color="#376091" face="Arial">
</font><b><caption>
<!------------------------------------------------------------------->
<! THIS SECTION FETCHES THE INFORMATION FROM THE MYSQL TABLE >
<!------------------------------------------------------------------->
<?php
$counter = array();
$last_wish_to_play = "";
$firstNAsAString = "";
while($row=mysql_fetch_array($result)){

//----------------------------------------------------------------------------------------------------
// THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED
//----------------------------------------------------------------------------------------------------
if($i > 0 AND $row['i_wish_to_play'] != $last_wish_to_play)
{
echo '<tr>
<td colspan="3">&nbsp;</td>
</tr>';
}
//------------------------------------------------------
// THIS SECTION ADDS HEADINGS
//------------------------------------------------------
if ($row['i_wish_to_play'] != $last_wish_to_play) {
echo '<tr>
<td colspan="3" align="center" bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>'.$row['i_wish_to_play'].'</b></font></td>
</tr>';
echo '<tr>
<td bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>FULL NAME</b></font></td>
<td align="center" bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>HANDICAP</b></font></td>
<td align="center" bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>CELL NUMBER</b></font></td>
</tr>';
}

echo '<tr><td bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">';
echo '<option value="'.strtoupper($row['surname']).', '.strtoupper($row['name']).'">'.strtoupper($row['surname']).', '.strtoupper($row['name']).'</option>';

echo '</td><td align="center" bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">';
echo $row['my_handicap_is'];

echo '</td><td align="center" bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">';
echo $row['cell_phone'];

if($row['i_wish_to_play'] != $last_wish_to_play)
{
// the first n words to extract
$n = 5;
// extract the words
$words = explode(" ", $row['i_wish_to_play']);
// chop the words array down to the first n elements
$firstN = array_slice($words, 1, $n-1);
// glue the 3 elements back into a spaced sentence
$firstNAsAString = implode(" ", $firstN);
}
if(!isset($counter[$firstNAsAString]))
$counter[$firstNAsAString] = 0;
else
$counter[$firstNAsAString]++;
$last_wish_to_play = $row['i_wish_to_play'];

$i++;
echo '</td></tr>';


}
echo '</table>';

?>

The othe rpart which shows the left hand side of the page is this part:




<!------------------------------------------------------------------>
<! THIS SECTION CHANGES THE MAIN HEADING >
<!------------------------------------------------------------------>
<table>
<td colspan="2" width="25%" align="center" bgcolor="#376091"><font style="font-size:12px" color="#FFFFFF" face="Arial"><b>TOTAL ENTRIES</b></font></td>
</table>
<!-------------------------------------------------------------------->
<! THIS SECTION COUNTS THE ROWS THAT ARE UNIQUE AND PROVIDES RESULT >
<!-------------------------------------------------------------------->
<?php
echo '<table border=1 bgcolor=#B5CCE4 bordercolor="#FFFFFF" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" cellspacing=0>';
foreach($counter as $key => $value)
{
echo '<tr>

<td align="center" width="10%" bgcolor="#B5CCE4"><font style="font-size:12px" color="#000000" face="Arial"><b>'.$value.'</b></font></td>
<td colspan="2" width="65%" align="center" bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">'.$key.'</font></td>
</tr>';
}
echo '</table>';
?>


I currently use a program called BlueVoda which is freely downloadable form the internet - WYSIWYG web builder

I would be so appreciatetive if you could help me there as it is where I would be going to.

Regards
Rob

Rob (SA)
10-19-2010, 04:44 AM
Hi John,

I have edited the text file and tried to insert back to the html.

Same problem - it is limiting me to the amount of characters in the file -really wierd.

The idea was a good one.

Regards
Rob

Rob (SA)
10-19-2010, 04:24 PM
Hi John,

I have managed to make the changes useing Cpanel - so the first part is done.

Thanks for your willingness to help me with it.

Without being presumpteous do you perhaps see your way to assist me with the second part - i.e making the link work so as to count to 80 and then close the tournament?

I look forward to your reply

Regards
Rob

jscheuer1
10-21-2010, 08:25 AM
A reason I asked about the database is that I'm not real up on that (MySQL in this case I think) or the PHP required to interface with it.

I'm pretty sure now that's what you're doing. I do know that if you want to count records and/or loop through them - that's pretty straightforward stuff. Unfortunately it's stuff I'm just not all that familiar with yet. It's on my list.

What I would suggest is opening a new thread in PHP:

http://www.dynamicdrive.com/forums/forumdisplay.php?f=11

Show them what you have as far as the PHP goes, give them a link to the output. Ask your question in terms of getting the output to look how you want it to look. You may also need to tell them about the structure of your database.

Or - I assume you got most of this stuff somewhere. There's probably documentation and a forum there. If either is any good, one and/or the other would probably be a better place to go to for your answers than anywhere on this forum.

Rob (SA)
10-21-2010, 08:00 PM
Hi John,

Thanks for the advice and assistance.

I will try the new thread and see where it leads.

Kind Regards
Rob

Rob (SA)
10-22-2010, 04:56 AM
Hi John,

I have had the thread closed by "DDADMIN" and advised to continue with the process on this thread.

I thought it was a differnet issue and accepted your advice.

No matter lets see hwta transpires.

Regards
Rob

jscheuer1
10-23-2010, 04:14 PM
I had no idea that by following my advice you would be opening a third thread on this. This really is a MySQL/PHP question and should never of been in javascript (my forte). So I guess (in order to satisfy that and ddadmin) I'll move it to PHP. I should also give you a warning about cross posting, but I think you get the idea. It probably could also use a new title - Using data from MySQL, with a see also to:

http://www.dynamicdrive.com/forums/showthread.php?p=239416

Rob (SA)
10-24-2010, 05:49 AM
Hi John,

Thaks for your reply and help - I never meant to cause any problems here and your warning / advice will be headed.

Thanks for moving the thread to the correct place.

I hope I will find reply soon.

Regards
Rob

bluewalrus
10-24-2010, 06:05 AM
Rob, you need to provide data about your database structure.

I gave you a schematic here

http://www.dynamicdrive.com/forums/showthread.php?t=58305

for how it could be set up. If that is not how you have it set up please let us know how it is set up and what the PHP relates to. Without this information we are just guessing.

Rob (SA)
10-24-2010, 06:46 AM
Hi Please,

Revert to the new link - provided by John below and all future replies will be made there.

I thanks you for your support in solving my problem

Regards
Rob

jscheuer1
10-24-2010, 07:44 AM
I think he means go here:

http://www.dynamicdrive.com/forums/showthread.php?p=239896#post239896