#19342 - 02/29/04 06:36 AM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Feb 2002
Posts: 7,202
Gremelin
Community Owner
|
Community Owner

Joined: Feb 2002
Posts: 7,202
Likes: 11
Portland, OR; USA
|
|
|
|
#19345 - 02/29/04 06:48 AM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Feb 2002
Posts: 7,202
Gremelin
Community Owner
|
Community Owner

Joined: Feb 2002
Posts: 7,202
Likes: 11
Portland, OR; USA
|
http://confess.undergroundnews.com/confessed.php?section=4 All it loads is a blank page... The EXACT code I'm using on confessed.php is (slightly differant than sintax): <?php require "connect.php"; ?>
<?php
$mysql_access = mysql_connect($host, $user, $pw) or die(mysql_error());
mysql_select_db($db) or die(mysql_error()); // make sure you add this ;)
?>
<?php
//the rand function in php see http://www.php.net/manual/en/function.rand.php
$random = rand(1, $highest_id_number_in_the_database);
$dg = mysql_query("Select *, DATE_FORMAT(date, '%H:%i on %d/%c/%Y') AS date2 from ugn_confession WHERE id = '$random'");
While($dg2 = mysql_fetch_array($dg)){
echo "".$dg2['type']."
";
echo "".$dg2['date']."
";
echo "".$dg2['id']."
";
echo "".$dg2['name']."
";
echo "".$dg2['confession']."
";
/* to add more info just
echo "any text you want to add ".$dg2['db_feild_name']."";
*/
}
?> See, what I'm goin for here is a little differant than what you think. See, there are 7 types of sin's, with 8 as miscelanious. Think of it as choosing a section. I want it so that people can basically do ?section=[number of the sin type] and it'll take and list a random sin that's in the database FOR that sin type...
|
|
|
#19346 - 03/01/04 02:55 AM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Dec 2002
Posts: 3,255
§intå×
|

Joined: Dec 2002
Posts: 3,255
Likes: 3
Maryland
|
well that is a horse of a different color. //**************************************************************
<?
//* referinf URL below *
//* http://confess.undergroundnews.com/confess.php?section=# *
//**************************************************************
//This code is assuming that type is your section
//number in the table at the top of this thread
//(post).
$dg = ("Select * FROM ugn_confession WHERE type = '$section'");
$num_rows = mysql_num_rows($dg);
$count = "1";
while($dg2 = mysql_fetch_array($dg)){
if($count == "1"){
$random1 = "".$dg2['id']."";
}else{
}
$count = $count++
if ($count == "$num_rows"){
$random2 = "".$dg2['id']."";
}else{
}
}
?> Then just use my code above again... Hmmmm this would only work if all section info was stored in sequential order.... In other words
Your_table
field1 feild2 type id
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
bla bla 1 1
bla bla 1 2
bla bla 2 3
bla bla 2 4
bla bla 2 5
bla bla 3 6
//
//The above would work but this would not
//
field1 feild2 type id
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
bla bla 1 1
bla bla 3 2
bla bla 2 3
bla bla 5 4
bla bla 6 5
bla bla 1 6
My advise is store each section in a different table to allow you to index the data easier. Some thing like this in the code.
if($section == "1"){
//query such and such table
}else if($section == "2"){
//query bla bla table
}else if($section == "3"){
//query this and that table
}
That would be easier than using one table.
|
|
|
#19347 - 03/01/04 07:54 AM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Feb 2002
Posts: 7,202
Gremelin
Community Owner
|
Community Owner

Joined: Feb 2002
Posts: 7,202
Likes: 11
Portland, OR; USA
|
|
|
|
#19348 - 03/02/04 10:44 AM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Dec 2002
Posts: 3,255
§intå×
|

Joined: Dec 2002
Posts: 3,255
Likes: 3
Maryland
|
|
|
|
#19350 - 03/02/04 12:53 PM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Dec 2002
Posts: 3,255
§intå×
|

Joined: Dec 2002
Posts: 3,255
Likes: 3
Maryland
|
Dude you can use the same code form the while function on. Like so.. <?
//*********************Start code for section 1*********************
if($section == "1"){
$random_number = rand(1,$highest_id_number_in_this_table);
$dg = mysql_query(SELECT * FROM ugn_confession1 WHERE id = '$random_number');
//*********************Start code for section 3*********************
}else if($section == "3"){
$random_number = rand(1,$highest_id_number_in_this_table);
$dg = mysql_query(SELECT * FROM ugn_confession2 WHERE id = '$random_number');
}
//after all the if statements you just do one while statement
While($dg2 = mysql_fetch_array($dg)){
echo "".$dg2['type']."
";
echo "".$dg2['date']."
";
echo "".$dg2['id']."
";
echo "".$dg2['name']."
";
echo "".$dg2['confession']."
";
} See the only thing that is different is you have to handle the rand(); function and mysql_query in the if, else statements. The rest is the same because the variable $dg is passed to while just the same. The reason is only one $dg = mysql_query(); function will be processed. Make sense? Also your table need to be constructed identicaly for this to work of course. Now you could do it in one table IF..... Section 1 is id numbers 1 - 500 Section 2 is id numbers 501 - 1000 Section 3 is id numbers 1001 - 1500 and so on This would be difficult to update dynamicaly though. But if you did this this way the first script I posted today would work. But the id's have to be sequential to do the random functions I coded. Of course, maybe you could put it into an array... hmmmmmm **note This may cause it to be slower for some reason. I have used arrays a bit lately and found they seem to slow things down a bit. But that is on my 2 servers Solaris OS running apache and Redhat9 Running apache $dg = ("SELECT * FROM you_table WHERE id = '$section'");
$count = "0"
$number_rows = mysql_num_rows($dg);
WHILE($dg mysql_fetch_array($dg)){
$ugn_array = $dg2;
}
$random_num = (0, $number_rows);
echo "".$ugn_array['$random_num']['type']."
";
and so on... that should work for you....
|
|
|
#19354 - 03/03/04 08:01 AM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Feb 2002
Posts: 7,202
Gremelin
Community Owner
|
Community Owner

Joined: Feb 2002
Posts: 7,202
Likes: 11
Portland, OR; USA
|
Damnit, now I'm confused about how to go about inputting the data! lol... Ok, see input page above, how would I go about making my page input into the differant databases, I know I'd use if/else statements, but i'm not entirely sure how to go about it... see: http://crap.undergroundnews.com/confess.zip for source.
|
|
|
#19355 - 03/03/04 08:41 AM
Re: confessed.php?section=4 to display tabledata for section
|
Joined: Dec 2002
Posts: 3,255
§intå×
|

Joined: Dec 2002
Posts: 3,255
Likes: 3
Maryland
|
Simple man... You have a select box with the various section names like so <?
session_start();
if(session_is_registered(your_session_name_here)){
//
//
//
//The above is to secure the form. So not just anyone can use it
//
//
//
//
?>
<form name=some_form id=some_form action="http://some_url.com">
<select name=select_name>
<option value=1>Section 1</option>
<option value=2>Section 2</option>
<option value=3>Section 3</option>
</select>
<!--
The rest of the form elements for db entry go here
-->
<input type=submit value=submit>
<?
//
//closing out the session { below
//
}
//
//
//
?> Then on the page the form data is sent to... <?
//
//Below is here so no on can submit using a URL hack
//
session_start();
if(session_is_registered(your_session_name_here)){
//
//
//Start checking for sections and processing data
//
//
if($section_name == "1"){
$dg = mysql_query(INSERT into Table_name (feild1, feild2, feild3,)VALUES ('$form_feild1', '$form_feild2', '$form_feild3'));
if($dg){
?>
<center>
Insert sucessful, you will be re-directed now.
<meta refresh=you_know_the_deal>
<?
}else{
?>
There is a issue at this time. Please try back later.
<?
echo "error ".mysql_error();
//rember to remove this when the script is 100% ready
?>
}
//
//
//Second section process
//
//
}else if($section == "2"){
$dg = mysql_query(INSERT into Table_name2 (feild1, feild2, feild3,)VALUES ('$form_feild1', '$form_feild2', '$form_feild3'));
if($dg){
?>
<center>
Insert sucessful, you will be re-directed now.
<meta refresh=you_know_the_deal>
<?
}else{
?>
There is a issue at this time. Please try back later.
<?
echo "error ".mysql_error();
//rember to remove this when the script is 100% ready
?>
}
}
?> Now to save yourself some time you could write a function. The coolest thing in php is the ability to write your own commands. Sooooo you can take this... if($section_name == "1"){
$dg = mysql_query(INSERT into Table_name (feild1, feild2, feild3,)VALUES ('$form_feild1', '$form_feild2', '$form_feild3'));
if($dg){
?>
<center>
Insert sucessful, you will be re-directed now.
<meta refresh=you_know_the_deal>
<?
}else{
?>
There is a issue at this time. Please try back later.
<?
echo "error ".mysql_error();
//rember to remove this when the script is 100% ready
?>
}
//
//
//Second section process
//
//
}else if($section == "2"){
$dg = mysql_query(INSERT into Table_name2 (feild1, feild2, feild3,)VALUES ('$form_feild1', '$form_feild2', '$form_feild3'));
if($dg){
?>
<center>
Insert sucessful, you will be re-directed now.
<meta refresh=you_know_the_deal>
<?
}else{
?>
There is a issue at this time. Please try back later.
<?
echo "error ".mysql_error();
//rember to remove this when the script is 100% ready
?>
}
}
?> and turn it into this insetion_cmd($table_name $section); See this link for info. http://us2.php.net/manual/en/functions.php#functions.user-defined Functions can save you tons of time. On tradebikes for example I have one function that creates drop down and/or text boxes on the fly on all forms. It sets the CSS attributes and populates the drop downs all dynamicaly. one drop down menu can be minimum 7 lines of code. I have it trimed down to one. and with a slight change it can be several other form elements. I trimed about 500+ lines off each bike entry page this way.
|
|
|
|
Forums41
Topics33,701
Posts68,795
Average Daily Posts0
|
Members2,173
Most Online1,567 Apr 25th, 2010
|
|
|
Okay WTF?
by HenryMiring on 09/27/17 08:45 AM
|
|
|
|
|
|
|
|