Forum Moderators: coopster
Here is the really messed up code that I have so far:
<?php
// Request one devotion
$query = "SELECT * FROM devo ORDER BY devo.id ASC LIMIT 1";
$result = mysql_query($query);
$i=0;
if($num=mysql_numrows($result))
where ($i < $num) {
//$variable=mysql_result($result,$i,"fieldname");
$id=mysql_result($result,$i,"id");
$title=mysql_result($result,$i,"devotitle");
$week=mysql_result($result,i,"devoweek");
$verse=mysql_result($result,$i,"devoverse");
$text=mysql_result($result,$i,"devotext");
$read=mysql_result($result,$i,"devoread");
//Get current week as a number
$week=date('W')
$j=0;
if($week($result))
while ($j < $week){
echo "
$row->ID <h2>$row->title</h2>
<h6>Week $row->week</h6>
<h4>$row->verse</h4>
<p>$row->text</p>
<p> </p>
<h3>Recommended reading - $row->verse</h3>
<br />\n";
}
$i++;
}
?>
What are the error messages you are receiving?
You might also want to take a look at the following thread: [webmasterworld.com...]
btw, Welcome to WebmasterWorld! :)
Here is what I was using to make it display one devotion.
// Connect to the server daqtabase server
$dbcnx = @mysql_connect('$server', '$username', '$password');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' . 'database server at this time.</p>');
}
if (!@mysql_select_db('life')) {
exit('<p>Unable to locate the Life ' .
'database at this time.</p>');
}
?>
<?php
// Request the titles of all the devotions
$result = @mysql_query('SELECT devotitle, devoweek, devotext, devoverse, devoread FROM devo ORDER BY devo.id ASC LIMIT 1');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display the title of each devotion in a paragraph
while ($row = mysql_fetch_object($result)) {
echo "
$row->ID
<h2>$row->devotitle</h2>
<h6>Week $row->devoweek</h6>
<h4>$row->devoverse</h4>
<p>$row->devotext</p>
<p> </p>
<h3>Recommended reading - $row->devoverse</h3>
<br />\n";
}
?>
$i = 0;
While ($i <= 53) {
"SELECT $i";
$i++;
}
while ($get_info = mysql_fetch_row($result))
{
foreach ($get_info as $field)
$id=mysql_result($result,$i,"id");
$title=mysql_result($result,$i,"devotitle");
$week=mysql_result($result,i,"devoweek");
$verse=mysql_result($result,$i,"devoverse");
$text=mysql_result($result,$i,"devotext");
$read=mysql_result($result,$i,"devoread");
echo "$field\n\n";
echo "\n";
}
Error:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 54 on MySQL result index 2 in C:\inetpub\wwwroot\mh_devotions_test_4.php on line 148
This is line 148:
$title=mysql_result($result,$i,"devotitle");
_____________________________________________________________________
$query = "SELECT * FROM devo WHERE id=$week_num";
$result = mysql_query($query);
$week_num = date('W');
while($row = mysql_fetch_row( $result )) {
echo"<h2>"$row['devotitle']"</h2>";
echo"<h6>"$row['Week devoweek']"</h6>";
echo"<h4>"$row['devoverse']"</h4>";
echo"<p"$row['devotext']"</p>";
echo"<p> </p>";
echo"<h3>Recommended reading - "$row['devoread']"</h3>";
echo"<br />\n";
}
Error:
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in C:\inetpub\wwwroot\mh_devotions_test_3.php on line 145
This is line 145:
echo"<h6>"$row['Week devoweek']"</h6>";
_____________________________________________________________________
<?php
// Request one devotion
$query = "SELECT * FROM devo ORDER BY devo.id ASC LIMIT 1";
$result = mysql_query($query);
if($num=mysql_numrows($result))
$i=0;
while ($i < 53) {
$i++;
$title=mysql_result($result,$i,"devotitle");
$week=mysql_result($result,i,"devoweek");
$verse=mysql_result($result,$i,"devoverse");
$text=mysql_result($result,$i,"devotext");
$read=mysql_result($result,$i,"devoread");
// Display each devotion in a paragraph
echo "
<h2>$title</h2>
<h6>Week $week</h6>
<h4>$verse</h4>
<p>$text</p>
<p> </p>
<h3> $read</h3>";
}
ERROR:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 2 in C:\inetpub\wwwroot\mh_devotions_test_1.php on line 134
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 2 in C:\inetpub\wwwroot\mh_devotions_test_1.php on line 136
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 2 in C:\inetpub\wwwroot\mh_devotions_test_1.php on line 137
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 2 in C:\inetpub\wwwroot\mh_devotions_test_1.php on line 138
Week 1
These are the lines:
133 $title=mysql_result($result,$i,"devotitle");
134 $week=mysql_result($result,i,"devoweek");
135 $verse=mysql_result($result,$i,"devoverse");
136 $text=mysql_result($result,$i,"devotext");
137 $read=mysql_result($result,$i,"devoread");
138
_____________________________________________________________________
I hope this isn't too much to post all at once but I wanted you to know that I have been working on it and just am not getting something.
Please HELP!? Thanks.
are you going to use a drop down for date?
do you aready have the date selection part figured out?
you can pass the date function a timestamp to get the week number for that time
I thought that what I was doing that with this code but, again, it didn't work.
$query = "SELECT * FROM devo WHERE devoweek=$week_num";
$week_num = date('W');
I am adding 52 devotions to the database so the id's would be 01-53 but I have also added a field called devoweek where the numbers would be 01-53. I was hoping to match the current date(W) to either the id or the devoweek to make it display the correct week.
>>are you going to use a drop down for date?
Right now I don't have an actual date in the database itself
>>do you aready have the date selection part figured out?
<p>I thought that date(W) would work but apparently not</p>
<blockquote>you can pass the date function a timestamp to get the week number for that time
I did try that and I get a neverending loop where devoweek 1 repeats itself down the page. Here is the code for that:
<?php
// Request devotion
$query = "SELECT * FROM devo";
$result = mysql_query($query);
$week = date('W', $timestamp);
$devo_week = 'devoweek';
$row = mysql_fetch_object($result);
while ($week=$devo_week){
echo "
<h2>$row->devotitle</h2>
<h6>Week $row->devoweek</h6>
<h4>$row->devoverse</h4>
<p>$row->devotext</p>
<p> </p>
<h3>Recommended reading - $row->devoread</h3>
<br />\n";
}
?>
<?php
// Request all devotions
$query = "SELECT * FROM devo";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
//define variables
$week_num = strftime("%W");
$devo_week = 'devoweek';
//while condition is true display on screen
while ($week_num == $devo_week){
echo"
<h2>$row->devotitle</h2>
<h6>Week $row->devoweek</h6>
<h4>$row->devoverse</h4>
<p>$row->devotext</p>
<p> </p>
<h3>Recommended reading - $row->devoread</h3>
<br />\n";
}
?>
normally (for me anywys) when the code returns emptyness, the code is coo, but th values passed/manipulated therin are awry
2 cents... idle observation from an ameteur
the logic works though
<?php
// Request all devotions
$query = "SELECT * FROM devo";
$result = mysql_query($query);
$devoarr = array();
while ($row = mysql_fetch_array($query)) {
$devoarr[] = array($row['devotitle'],$row['devoweek'],$row['devoverse'],$row['devotext'],$row['devoread']);
}
// get week number and multiply to get rid of the
// leading 0 and -1 to fit with the array
// which should be 0 to 52
$week_num = (strftime("%W") * 1) - 1;
// use week number to access proper element of devoarr
echo'<h2>',$devoarr[$week_num][0],'</h2><h6>Week ',$devoarr[$week_num][1],'</h6><h4>',$devoarr[$week_num][2],'</h4><p>',$devoarr[$week_num][3],'</p><p> </p><h3>Recommended reading - ',$devoarr[$week_num][4],"</h3><br />\n";
?>
I built the result set into an array and then just used the weeknum to access the appropriate element of the array.
oh, and you don't need to hire someone, you're close and you're trying so we like to help those that are working to help themselves ;)
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\inetpub\wwwroot\mh_devotions_test_10.php on line 127
Week
Recommended reading -
<?php
// Request all devotions
$query = "SELECT * FROM devo";
$result = mysql_query($query);
$devoarr = array();
while ($row = mysql_fetch_array($result)) {
$devoarr[] = array($row['devotitle'],$row['devoweek'],$row['devoverse'],$row['devotext'],$row['devoread']);
}
// get week number and multiply to get rid of the
// leading 0 and -1 to fit with the array
// which should be 0 to 52
$week_num = (strftime("%W") * 1) - 1;
// use week number to access proper element of devoarr
echo'<h2>',$devoarr[$week_num][0],'</h2><h6>Week ',$devoarr[$week_num][1],'</h6><h4>',$devoarr[$week_num][2],'</h4><p>',$devoarr[$week_num][3],'</p><p> </p><h3>Recommended reading - ',$devoarr[$week_num][4],"</h3><br />\n";
?>
You have no idea how long I have been trying to work this out. I really had no idea what I was getting into when I said that I would learn this so she could have her devotions.
I knew that I wanted to learn it anyway but I see now that this will take more than a few months to get the hang of it. There are so many choices; I didn't know whether to use mysql_fetch_array or object or row and it seemed every time you changed it all the syntax changed with it.
I was way over my head and I really appreciate you helping me out.
Really, I would be glad to pay you. It is so worth it to know that it is done. Thank you again.
$query = "SELECT * FROM devo WHERE devoweek=$week_num";
$week_num = date('W');
Your problem in that snippet was that you tried to use
$week_numbefore you had actually defined it. Following on that line of thinking though, you could write a simpler bit of code to achieve the same results as the code in Jatar's post, by letting MySQL do most of the work for you. It's gentler on your server (not a big deal, but why not), and nice and tidy to boot:
<?// Get the week number as a number (1-53)
// You can subtract one if you need (0-52)
// Multiplying by one to drop the leading 0
$week_num = strftime("%W") * 1;// Make a query which searches for the right week
// You were on the right track a couple posts ago
// But you had defined $week_num after defining $query
$query = "SELECT * FROM `devo` WHERE `devoweek` = $week_num";
$result = mysql_query($query);// Make your associative array automatically
// No need to do it the hard way, as long as you
// Can use your column names as the array keys
$devoarr = mysql_fetch_assoc [us2.php.net]($result);// Just call out the proper column name for each spot
// Also added in some line breaks (\n) for pretty code
echo "<h2>".$devoarr['devotitle']."</h2>\n
<h6>Week ".$devoarr['devoweek']."</h6>\n
<h4>".$devoarr['devoverse']."</h4>\n
<p>".$devoarr['devotext']."</p>\n
<p> </p>\n
<h3>Recommended reading - ".$devoarr['devoread']."</h3>\n
<br />\n";?>