Forum Moderators: coopster

Message Too Old, No Replies

How do I extract the data of an individual entry?

         

thewackonerd

12:35 am on Jan 12, 2006 (gmt 0)

10+ Year Member



Hi, I want to pull data from a table and display each line but not use a repeat region.

The database table design is as follows

-------------
Name, Type, Size, Decimals, Null, Primary key
-------------
Id, Integer, 11, 0, no, yes
Setting, Varchar, 100, 0, No
Value, Longtext, -1, 0, no
--------------

So I get a table of data like this.
--------------------
Id, Setting, value
---------------------
1, sitename, memo
2, siteurl, memo
3, Siteemail, memo
4, Copynotice, memo
--------------------

I then create a record set called ‘rs_settings’

How do I extract the data of an individual entry? say the 4th, 7th and 10th entry

Thank you

Frank

jatar_k

1:38 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld thewackonerd (entertaining nick ;) ),

you lost me a bit

if your keys are sequential you would then grab 4, 7 and 10 but I don't think that is the answer you are looking for.

Anytime you want to select a set of rows you need to define common criteria that will identify only those rows.

I am not exactly sure what it is you need to find among your rows.

Halfdeck

1:38 am on Jan 12, 2006 (gmt 0)

10+ Year Member



First, connect to MYSQL:

mysql_connect(SERVER, YOURUSERNAME,PASSWORD);
mysql_select_db(DATABASENAME);

// Your query:

$query = "SELECT *
FROM YOURTABLENAME
WHERE (id=4 or id=7 or id=10)";

$result = mysql_query($query); // pull data from MYSQL

// then display the results

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "ID: " .$row['id'] ." SETTING: " .$row['setting'] ." VALUE: " .$row['value'];
}

thewackonerd

2:03 am on Jan 12, 2006 (gmt 0)

10+ Year Member



Hi Guys and thanks for helping me out.

I use dreamweaver to create my sites so I am not a true "php" programmer.

What I want to do is this:

The database is auto incremental
I have 2 columns: Settings and Value

I enter a new setting and value via the back end and it is automaticly assigned a number which is the primary key.

lets say there are 50 entrys

On a page in the front end of my site I want to insert the value of some of the entrys into the page. (like the site name (value 1), email address (value 3), meta tages (value 7), ect)

I hope that this helps you understand what I am tring to do.

thank you

thewackonerd

2:11 am on Jan 12, 2006 (gmt 0)

10+ Year Member



Halfdeck

I believe you are on the right track for what I want to do, I will have a fiddle with it,

thanks

jatar_k

5:39 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if they are settings and there will only be a single name for each you could just use the name as well

select setting, value from mytable where setting='sitename' or setting='emailaddress' or setting='metatags';

or another version of the multiple id

select * from mytable where id in (1,3,7);

if you were looking for a single value you could grab that

select value from mytable where setting='sitename';

thewackonerd

5:57 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



Hi jatar_k
I know how to pull individual entrys out but I want to multipule entries but not use a repeat region. I can see the advice I am getting is on the right track but I am not sure how I implement it, where do I put each bit, is it php enclosed?

jatar_k

6:47 pm on Jan 13, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> but not use a repeat region

I don't quite understand what you mean by that

maybe try testing Halfdeck's example and see if that clarifies

you could also look at this thread for a little more explanation about getting data from mysql [webmasterworld.com]

might help

thewackonerd

11:53 pm on Jan 14, 2006 (gmt 0)

10+ Year Member



I am not getting it so I will put the code up for you to see and then if you could point out my mistake I would be grateful and educated at the same time.

rs_settings is the RS that I want to pull out the data from but I just dont know what to put in the body to do this.


<?php
//Connection statement
require_once('Connections/datasource.php');

// begin Recordset
$query_rs_config = "SELECT * FROM config";
$rs_config = $datasource->SelectLimit($query_rs_config) or die($datasource->ErrorMsg());
$totalRows_rs_config = $rs_config->RecordCount();
// end Recordset

// begin Recordset
$query_rs_menu = "SELECT * FROM menu";
$rs_menu = $datasource->SelectLimit($query_rs_menu) or die($datasource->ErrorMsg());
$totalRows_rs_menu = $rs_menu->RecordCount();
// end Recordset

// begin Recordset
$colname__rs_cat = '-1';
if (isset($_GET['id'])) {
$colname__rs_cat = $_GET['id'];
}
$query_rs_cat = sprintf("SELECT * FROM categories WHERE cat_id = %s", $colname__rs_cat);
$rs_cat = $datasource->SelectLimit($query_rs_cat) or die($datasource->ErrorMsg());
$totalRows_rs_cat = $rs_cat->RecordCount();
// end Recordset

// begin Recordset
$colname__rs_subcat = '-1';
if (isset($_GET['subcat_id'])) {
$colname__rs_subcat = $_GET['subcat_id'];
}
$query_rs_subcat = sprintf("SELECT subcat_id, mcat_id, subcat_name FROM subcategories WHERE subcat_id = %s ORDER BY mcat_id ASC", $colname__rs_subcat);
$rs_subcat = $datasource->SelectLimit($query_rs_subcat) or die($datasource->ErrorMsg());
$totalRows_rs_subcat = $rs_subcat->RecordCount();
// end Recordset

// begin Recordset
$colname__Recordset2 = '-1';
if (isset($_GET['id'])) {
$colname__Recordset2 = $_GET['id'];
}
$query_Recordset2 = sprintf("SELECT subcat_id, mcat_id, subcat_name FROM subcategories WHERE mcat_id = '%s' ORDER BY subcat_name ASC", $colname__Recordset2);
$Recordset2 = $datasource->SelectLimit($query_Recordset2) or die($datasource->ErrorMsg());
$totalRows_Recordset2 = $Recordset2->RecordCount();
// end Recordset

// begin Recordset
$colname__rs_settings = '-1';
if (isset($_POST['id'])) {
$colname__rs_settings = $_POST['id'];
}
$query_rs_settings = sprintf("SELECT * FROM settings WHERE id = %s", $colname__rs_settings);
$rs_settings = $datasource->SelectLimit($query_rs_settings) or die($datasource->ErrorMsg());
$totalRows_rs_settings = $rs_settings->RecordCount();
// end Recordset

//PHP ADODB document - made with PHAkt 3.6.0
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php //PHP ADODB document - made with PHAkt 3.6.0?>
<title><?php echo $rs_cat->Fields('cat_name');?> - <?php echo $rs_config->Fields('sitename');?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="<?php echo $rs_cat->Fields('cat_keywords');?>">
<meta name="description" content="<?php echo $rs_cat->Fields('cat_description');?>">
<meta name="title" content="<?php echo $rs_config->Fields('sitename');?>" />
<meta name="language" content="English" />
<meta name="author" content="<?php echo $rs_config->Fields('sitename');?>" />
<meta name="copyright" content="<?php echo $rs_config->Fields('sitename');?>" />
<meta name="robots" content="ALL" />
<meta name="revisit-after" content="7 days" />
<meta name="reply-to" content="<?php echo $rs_config->Fields('siteemail');?>" />
<meta name="document-rights" content="Copyrighted Work" />
<meta name="document-type" content="Web Page" />
<meta name="document-rating" content="General" />
<meta name="document-distribution" content="Global" />
<meta name="document-state" content="Dynamic" />
<script src="js/dropdown.js" type="text/javascript">
</script>
<link href="css/css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="751">
<tbody><tr>
<td align="center">
<img src="images/logo.gif" width="300" height="80">
</td>
</tr>
<tr>
<td>

<?php include("menu_top.php");?>
<br>
<?php WHAT GOES IN HERE TO PULL THE INFO FROM RS_SETTINGS ;?>
</td>
</tr>
<tr>
<td>
<table class="contentTable" align="center" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td width="370" rowspan="2" align="left" valign="top"><img src="images/<?php echo $rs_cat->Fields('cat_image');?>" width="370"><br>
</td>
<td width="100%" align="left" valign="top" class="bodytext">
<p class="bodytxt"><span class="bodytxt"><br>
<img src="images/<?php echo $rs_cat->Fields('cat_heading');?>" align="left"></span></p><br>

</td>
</tr>
<tr>
<td align="left" valign="top" class="bodytext"><div class="bodytext"><?php echo $rs_cat->Fields('cat_content');?></div></td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td>
<div align="center">
<table class="bottomNav" align="center" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td width="372" align="center" class="copyright">

<SCRIPT LANGUAGE="JavaScript">
<!--

today=new Date();
y0=today.getFullYear();

// end hiding --->
</SCRIPT>
© <SCRIPT LANGUAGE="JavaScript">
<!--- Hide from old browsers
document.write(y0);
// end hiding --->
</SCRIPT>
Avoca Bouddi

</td>
<td width="377" align="right">

<?php
// Show IF Conditional region1
if (@$rs_cat->Fields('cat_id') == @$Recordset2->Fields('mcat_id')) {
?>
<form id="form2" method="post" action="">
<select name="drop down" id="drop down" onChange="MM_jumpMenu('parent',this,0)">
<option value="#" selected="selected">select</option>
<?php
while (!$Recordset2->EOF) {
?>
<option value="subcat.php?id=<?php echo $Recordset2->Fields('mcat_id');?>&subcat_id=<?php echo $Recordset2->Fields('subcat_id');?>"><?php echo $Recordset2->Fields('subcat_name');?></option>

<?php
$Recordset2->MoveNext();
}
?>
</select>
</form>

<?php
// else Conditional region1
} else {?>
&nbsp; <?php }
// endif Conditional region1
?>
</td>
</tr>
</tbody></table>
</div>
</td>
</tr>
</tbody></table>
</div>
<?php include("sub_footer.inc.php");?>
</body></html>
<?php
$Recordset2->Close();

$rs_settings->Close();

$rs_config->Close();

$rs_menu->Close();

$rs_cat->Close();

$rs_subcat->Close();

$Recordset2->Close();
?>