Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
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
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
Damn it!!! mad


Gizmo PLEASE fix this [censored] 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']."";
*/
}

Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
Code
<html></html><?php ?>


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
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
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
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
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
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
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
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.

Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
mmmk


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
See post above

Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
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 smirk... 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
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
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....

Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
'eh I'll screw with it in the morning wink


Donate to UGN Security here.
UGN Security, Back of the Web, and VNC Web Services Owner
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
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?

Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
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
Joined: Feb 2002
Posts: 7,203
Likes: 11
Community Owner
OP Offline
Community Owner
Joined: Feb 2002
Posts: 7,203
Likes: 11
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
Joined: Dec 2002
Posts: 3,255
Likes: 3
UGN Elite
Offline
UGN Elite
Joined: Dec 2002
Posts: 3,255
Likes: 3
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.


Link Copied to Clipboard
Member Spotlight
Posts: 30
Joined: June 2002
Forum Statistics
Forums41
Topics33,840
Posts68,858
Average Daily Posts1
Members2,176
Most Online3,253
Jan 13th, 2020
Latest Postings
Where and how do you torrent?
by danni75 - 03/01/24 05:58 AM
Animation,
by JohanKaariainen - 08/15/19 01:18 AM
Blackbeard.....
by Gremelin - 10/03/18 07:02 PM
my old account still exists!
by Crime - 08/10/18 02:47 PM
Okay WTF?
by HenryMiring - 09/27/17 01:45 AM
The History Thread...
by Gremelin - 08/11/17 12:11 PM
My friend NEEDS your HELP!
by Lena01 - 07/21/17 12:06 AM
I'm having fun with this guy.
by gabithompson730 - 07/20/17 01:50 AM
I want to upgrade my phone
by gabithompson730 - 07/20/17 01:49 AM
Doom 3
by Cyrez - 09/11/14 08:58 PM
Amazon Gift Card Generator/KeyGen?te
by Gecko666 - 08/22/14 09:21 AM
AIM scene 99-03
by lavos - 09/02/13 08:06 AM
Planetside 2
by Crime - 03/04/13 07:10 AM
Beta Testers Wanted
by Crime - 03/04/13 06:55 AM
Hello Everyone
by Gremelin - 02/12/12 06:01 PM
Tracfone ESN Generator
by Zanvin Green - 01/18/12 01:31 PM
Python 3 issue
by Testing - 12/17/11 09:28 PM
tracfone airtime
by Drache86 - 07/30/11 03:37 AM
Backdoors and the Infinite
by ZeroCoolStar - 07/10/11 03:52 AM
HackThisZIne #12 Releaseed!
by Pipat2 - 04/28/11 09:20 PM
gang wars? l33t-wars?
by Gremelin - 04/28/11 05:56 AM
Consolidate Forums
by diggin2deep - 04/21/11 10:02 AM
LAN Hacking Noob
by Gremelin - 03/12/11 12:42 AM
Top Posters
UGN Security 41,392
Gremelin 7,203
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Likes Received
Ghost 2
Crime 1
Ice 1
Dartur 1
Cyrez 1
Powered by UBB.threads™ PHP Forum Software 7.7.5