Jump to content

Same page view query


tsetsuit

Recommended Posts

Ok having a bit of an issue with a calendar I am building. This is my first build using PHP so I am very new to it please let me know if I am messing anything up in process.

 

for the quick and simple, I am trying to have a link post a sql query in same page. In the calendar all you see if the type of request such as "meeting" , "maintenance" , or "other" the date you schedule it.

I have the input page to datebase working fine using a <form action='insert.php' method='post'> (code) </form>

 

Now the problem I am having is if i click on meeting, maintenance or other i want it to run a statement like

 

   1.  
   2. ("select * from postings where id = (id of the posting)");
   3.  

 

now what I do not know how to do is get the id of the posting by clicking on that link to run query against it.

 

I have read through $_get statements to get the id but I am really still trying to figure that out completely for getting table ids. Plus I want to link this on same page so i don't think doing a

Line number On/Off | Expand/Contract

   1.  
   2. $id = $_get('id') <a href='page.php?=$id>page</a>
   3.  

 

 

will work because that posts to a new page.

 

I have really been fighting this for last 2-3 days and tried to figure it out on my own before posting and had no luck.

posting some of the usefull code and datebase structure up below if anyone has any advice would be much appreciated. Thank you

 

 

SQL database info

changed some of the numbers and letters in database to prevent conflicts such as month=m0nth or date=da17

    * id (auto_increment)

    * m0nth

    * da17

    * year

    * user_id

    * type

    * subject

    * p0sting

    * emails

 

 

 

This is what i use to populate the calendar with the scheduled dates, I know I still need to add mysql_real_escape_string into my select statements for security, still working on reading through how that works will input before I complete this.

 

   1.  
   2.     $txtmon = "'" . date("F", $date) . "'";
   3.     $now = getdate();
   4.  
[code]

[code=php]
   1.  
   2.  
   3.     if( $now['mday'] == $day && $now['month'] == date("F", $date) )
   4.         {
   5.             echo "<td class='test' align='top' valign='left'><a href='test2.html'>" . $day . "</a>";
   6.             echo "<table width=30px height=60px><tr><td class='inner' align='top' valign='left'>";
   7.                 $posting = mysql_query("SELECT type,rows FROM postings WHERE da13=$day AND m0nth=$txtmon");
   8.                 while($row = mysql_fetch_array($posting))
   9.                       {
  10.                       echo "<br />";
  11.                       echo "<a href=''>" . $row['type'] . $row['rows'] . "</a>";
  12.                       echo "<br />";
  13.                       }
  14.             echo "</td></tr></table>";
  15.             echo "</td>";
  16.         } else {
  17.            
  18.             echo "<td class='dat' align='top' valign='left'><a href='test2.php'>" . $day .  "</a>";
  19.             echo "<table width=30px height=60px><tr><td class='inner' align='top' valign='left'>";
  20.                 $posting2 = mysql_query("SELECT type,rows FROM postings WHERE da13=$day AND m0nth=$txtmon");
  21.                 while($row = mysql_fetch_array($posting2))
  22.                       {
  23.                       echo "<br />";
  24.                       echo "<a href=''>" . $row['type'] . $row['rows'] . "</a>";
  25.                       echo "<br />";
  26.                       }
  27.             echo "</td></tr></table>";
  28.             echo "</td>";
  29.            
  30.         };
  31.     }
  32.  
  33.  

 

 

I want to post the SQL query in a jquery accordion to the right of the calendar. So when you click on the scheduled meeting or maintenance it pulls the information open to the right for the subject and who is getting e-mailed for it.The Jquery part i have taken care of I just need it to post on same page.

 

I have a cron job doing the e-mailing which is working fine.

Please any information would be much appreciated thank you

Link to comment
Share on other sites

I have it right now just showing the type and the rows in the date. So when i click on type i need it to show the month date year subject email post all the rest of the database in a box to the right of the whole calendar. I have everything figured out other then when i click how do i bind that link to the data in my database show it shows the data listed to right. This is difficult to explain sorry. I can post more code from the input page and more of the calendar page if needed.

 

btw 'rows' in my mysql database is my primary auto_increment that's the value i need to find to run do something like

$query = mysql_query("select * from postings where rows=(this is part i don't know how to do)" );

while($row = mysql_fetch_array($query))
{
echo $row['type'] . "<br/>";
echo $row['subject'] . "<br/>"; 
echo $row['p0sting] . "<br/>";
}

 

oops had to do an edit on that was way off on first example

 

Link to comment
Share on other sites

$query=mysql_query("select * from posting order by id desc");
while($query=mysql_fetch_array($query)){
echo $row["subject"].": ".$row["p0sting"]." by ".$row["user_id"]."<br>\n";
}

 

that is a simple query, notice I put * on the query, that will select ALL information available from that table, rather than type,rows... also the order the posting will how will be newest posts first (larger numbers) as ID is increment it will grow with new posting.

 

enjoy

 

Link to comment
Share on other sites

Only problem with that is that it will show all postings I have in order, I just want the one posting that corresponds with the item i am clicking on. Hmmm.... example time

lets say you input 7 scheduled items into a database.

now when you look at the calendar you see all the scheduled items in the calender under the date you scheduled them but only thing you see if the type of item you scheduled not any of the information.

Now you want to be able to click on one of those scheduled items and find the information that directly relates to that schedule such as the subject, or who it will e-mail for notification.

that is the problem i am having when i do this query

$sql = mysql_query("SELECT * FROM Postings where rows=(look at note below)")

I don't know how to get the row value from clicking on that. I understand how to post everything but i just want that one row that corresponds with the scheduled maintenance or meeting or other.

I really hope that helps explain it better this thing is driving me nuts.

Link to comment
Share on other sites

well first you would have to list the item... then you would have to pull it back... so if your url requests lets just say ?id=1

 

your code would be

if($_GET["id"]!=NULL){
$query=mysql_query("select * from posting where id='$_GET[id]'");
while($query=mysql_fetch_array($query)){
echo $row["subject"].": ".$row["p0sting"]." by ".$row["user_id"]."<br>\n";
}
}

Link to comment
Share on other sites

Ok ajax got me closer to where  I want to be but I end up right back at the same questions. when i click on the link to run the query how do I run a query against a field.

so say you click on This link and the way that link was put there is off of a statement like

 
$url = "whatever"
$sql= mysql_query("SELECT link FROM table where name=$url");

while($row = mysql_fetch_array($sql))
{
    echo "so say you click on" . "<a href onclick=switch($id)>" . $row['link'] . "</a>" . "and the way";
}

 

ok so say that code is real and that when i click on the link i want to run this query

 

 
$sql = mysql_query("Select * from table where id="whatever the id is of that row");

<ajax to insert it on same page>


 

I am still stuck where I don't know how to get the id of the row to displace it all on the page.

Ajax showed me how to display it on same page that helped me get to next step after i figure this one out.

I am guessing either i am being very dense about using $_get['id'] or i have been explaining myself wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.