Your browser does not seem to support CSS. If images appear below, please disregard them.
It appears that you're running an Ad-Blocker. This site is monetized by Advertising and by User Donations; we ask that if you find this site helpful that you whitelist us in your Ad-Blocker, or make a Donation to help aid in operating costs.
Previous Thread
Next Thread
Print Thread
Rate This Thread
#19340 - 02/28/04 05:46 PM confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
Ok, i have the following table:

Quote:
confessed.php?section=4
It'll take and list a random item of the "type" sction... I guess you'd probably need to see it to see what I'm tryin to do, so you can check out http://confess.undergroundnews.com/ I'm mainly making this script out of sheer boredom and trying to check how things work...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Sponsored Links
#19341 - 02/28/04 08:46 PM Re: confessed.php?section=4 to display tabledata for section  
Joined: Dec 2002
Posts: 3,255
§intå× Offline
§intå×  Offline


Joined: Dec 2002
Posts: 3,255
Likes: 1
Maryland
Damn it!!!


Gizmo PLEASE fix this fucking no HTML tag crap in the code tags. I posted exactly what you wanted, but UBB would not post it besace I had > and <'s in the code.


Code:
//php intro tage here
//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 * from ugn_confession WHERE id = '$random'");
While($dg2 = mysql_fetch_array($dg)){
echo "".$dg2['type'].""; 
/* to add more info just 
echo "any text you want to add ".$dg2['db_feild_name']."";
*/
}

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

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
Code:
<html></html><?php ?>


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#19343 - 02/29/04 06:36 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
works just fine for me... be sure you enclose the tags within [code][/code]


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#19344 - 02/29/04 06:43 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
Code:
<?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 * from ugn_confession WHERE id = '$random'");
   While($dg2 = mysql_fetch_array($dg)){
   echo "".$dg2['type'].""; 
   /* to add more info just 
   echo "any text you want to add ".$dg2['db_feild_name']."";
   */
}
?>
Looks all fine and dandy, but I don't see anything in there to take and do section=4...

See, all the differant types are 1-8, I'd want section= to take and load a type, but a random sin of said type...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Sponsored Links
#19345 - 02/29/04 06:48 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
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):

Code:
<?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...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#19346 - 03/01/04 02:55 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Dec 2002
Posts: 3,255
§intå× Offline
§intå×  Offline


Joined: Dec 2002
Posts: 3,255
Likes: 1
Maryland
well that is a horse of a different color.

Code:
//**************************************************************
<?
//*  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

Code:
 
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.


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,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
mmmk


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#19348 - 03/02/04 10:44 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Dec 2002
Posts: 3,255
§intå× Offline
§intå×  Offline


Joined: Dec 2002
Posts: 3,255
Likes: 1
Maryland
See post above

#19349 - 03/02/04 10:58 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
Very interesting... I may go your route, I wanted to do it with the smallest set of tables possible, but I guess that isn't too possible :/... Ah well, it'll only take a few seconds to refine what I need...

One question, if I use them with each type having it's own query, what would the query be to echo the data to the page with only one row but have it randomize for each time it's posted...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Sponsored Links
#19350 - 03/02/04 12:53 PM Re: confessed.php?section=4 to display tabledata for section  
Joined: Dec 2002
Posts: 3,255
§intå× Offline
§intå×  Offline


Joined: Dec 2002
Posts: 3,255
Likes: 1
Maryland
Dude you can use the same code form the while function on. Like so..


Code:
<?
//*********************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

Code:
$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....

#19351 - 03/02/04 07:06 PM Re: confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
'eh I'll screw with it in the morning


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#19352 - 03/03/04 06:45 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Dec 2002
Posts: 3,255
§intå× Offline
§intå×  Offline


Joined: Dec 2002
Posts: 3,255
Likes: 1
Maryland
Well it is now 17:43 local to me and Shhhh....


/me listens to crikets......

*churp churp churp*


Did it work, Which way did you go? Questions?

#19353 - 03/03/04 06:49 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
Portland, OR; USA
Well, I'm GOING to go with the seperate databases, but I'm tryin to think of the best route to go with the entering of info heh...


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#19354 - 03/03/04 08:01 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Feb 2002
Posts: 7,195
Gremelin Offline
Community Owner
Gremelin  Offline

Community Owner

Joined: Feb 2002
Posts: 7,195
Likes: 3
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.


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
#19355 - 03/03/04 08:41 AM Re: confessed.php?section=4 to display tabledata for section  
Joined: Dec 2002
Posts: 3,255
§intå× Offline
§intå×  Offline


Joined: Dec 2002
Posts: 3,255
Likes: 1
Maryland
Simple man...

You have a select box with the various section names like so

Code:
<?
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...

Code:
<?
//
//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...
Code:
  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


Code:
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.


Member Spotlight
Crime
Crime
SC, usa
Posts: 506
Joined: March 2002
Show All Member Profiles 
Forum Statistics
Forums45
Topics47,517
Posts82,687
Average Daily Posts7
Members2,159
Most Online1,567
Apr 25th, 2010
Latest Postings
Top Posters(All Time)
UGN Security 40,681
Gremelin 7,195
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Liked Users (All Time)
§intå× Likes: 1
Cold Sunn Likes: 1
Crime Likes: 1
Cyrez Likes: 1
Ghost Likes: 1
Gremelin Likes: 4
Ice Likes: 1
unreal Likes: 1
Top Liked Users (30 Days)
No Data Found
Powered by UBB.threads™ PHP Forum Software 7.6.0
(Snapshot build 20160902)